在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
使用 out传值的时候仅仅是将变量名(箱子)拿过来,并不会管之前是什么值 Console.Write("请输入a="); //使用return如何返回多个值 Program hanshu = new Program(); string[] array = hanshu.fanhui().Split('-'); 函数练习: { //无参有返 public int assd() { int sum = 0; for (int i = 0; i < 7;i++ ) { if (i == 0) { sum = 2; } else { sum = 2 * (sum + 1); } } return sum; } static void Main(string[] args) { Program hanshu = new Program(); int s = hanshu.assd(); Console.WriteLine(s); Console.ReadLine(); 2.掷骰子,投几走几步,逢3进1,逢5退1,逢7进2,逢0退4,求投几次后一共走了多少步? //有参有返 public int bu(int s) { int bu = 0; Random ran = new Random(); for (int i = 0; i < s; i++) { int a = ran.Next(1, 7); bu += a; if (bu % 10 == 3) { bu += 1; } else if (bu % 10 == 5) { bu -= 1; } else if (bu % 10 == 7) { bu += 2; } else if (bu % 10 == 0) { bu -= 4; } else { continue; } } return bu; } static void Main(string[] args) { Program hanshu = new Program(); Console.Write("输入您投的次数:"); int x = hanshu.bu(int.Parse(Console.ReadLine())); Console.WriteLine(x); Console.ReadLine();
//无参有返 public string d() { Random ran = new Random(); int fen = 0; int i = 1; int c = 0; for (; ; ) { int s = ran.Next(1, 21); if (s < 17) { c++; if (c == 5) { fen -= 2; c = 0; } } else if (s < 20) { fen += 4; } else { fen += 7; } i++; if (fen >= 100) { break; } } return "需要" + i + "次,才能达到100分"; } static void Main(string[] args) { Program hanshu = new Program(); string s = hanshu.d(); Console.WriteLine(s); Console.ReadLine();
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论