myam刚接触Java,我的老师让我制作一个打印随机数的程序。首先,应该询问用户最大数量是多少,然后应该打印该范围内的数字。这是我给出的代码,我很困惑如何使用它。如果有人知道怎么做,请帮助,谢谢。
public class RandomNmbers {
public static void main(String [] args){
EasyReader console = new EasyReader();
System.out.println ("What is the maximum number?");
{ int maxRandomNum = console.readInt();
String RandomNum = null;
System.out.println ("The random number is" + RandomNum);
}
}
public static int getRandomNumber(int max)
{int num = (int) (Math.random() * max) + 1; return num;}
int count = 1;
private int numToPrint;
}
答案 0 :(得分:0)
import java.util.Scanner;
public class RandomNumbers {
//int count = 1;
private static int numToPrint;
public static void main(String [] args){
Scanner sc = new Scanner(System.in);
System.out.println ("What is the maximum number?");
int maxRandomNum = sc.nextInt();
String RandomNum = Integer.toString(RandomNumbers.getRandomNumber(maxRandomNum));
numToPrint=Integer.parseInt(RandomNum);
System.out.println ("The random number is" + RandomNum);
}
public static int getRandomNumber(int max)
{
int num = (int) (Math.random() * max) + 1;
return num;
}
}
这段代码应该可以使用,带有扫描仪的Switched EasyReader,除了你的代码之外,还有一些东西缺失。