这道java题怎么做啊? 50
在“JSJ17”项目中创建“sy2_6.java”程序,要求从键盘上输入1-4的数字,对应产生1-4位的随机数。...
在“JSJ17”项目中创建“sy2_6.java”程序,要求从键盘上输入1-4的数字,对应产生1-4位的随机数。
展开
展开全部
public class sy2_6 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入数字1-4");
int num = scanner.nextInt();
Random random = new Random();
switch (num) {
case 1:
System.out.println(random.nextInt(10));
break;
case 2:
System.out.println(random.nextInt(90) + 10);
break;
case 3:
System.out.println(random.nextInt(900) + 100);
break;
case 4:
System.out.println(random.nextInt(9000) + 1000);
break;
}
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入数字1-4");
int num = scanner.nextInt();
Random random = new Random();
switch (num) {
case 1:
System.out.println(random.nextInt(10));
break;
case 2:
System.out.println(random.nextInt(90) + 10);
break;
case 3:
System.out.println(random.nextInt(900) + 100);
break;
case 4:
System.out.println(random.nextInt(9000) + 1000);
break;
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询