在命令提示符下运行时,
System.out.println(Num + " is prime!");
System.out.println("Press N to put in another number or S to stop");
Num
是int
这就是出现的结果:
有没有办法对付它,还是我应该处理它?</ p>
答案 0 :(得分:1)
package e1;
import java.util.Scanner;
public class E1 {
public static void main(String[] args) {
int hCount = 0;
int tCount = 0;
Scanner input = new Scanner(System.in);
System.out.print("How many coins should be tossed? ");
int coinsCount = input.nextInt();
for (int i=0; i < coinsCount; i++) {
if (Math.random() < 0.5) {
System.out.println("Heads");
hCount++;
} else {
System.out.println("Tails");
tCount++;
}
}
System.out.println("Heads: "+hCount+", Tails: "+tCount);
}
}
编辑:添加更多信息以充实这里的谜团。
java.lang.String.valueOf将正确解析您的Number,因为简单地添加一个带字符串的Number会因编译器而异。