使用println

时间:2017-11-18 02:02:18

标签: java println

在命令提示符下运行时,

System.out.println(Num + " is prime!");
System.out.println("Press N to put in another number or S to stop");

Numint

的位置

这就是出现的结果:

This is what comes out

有没有办法对付它,还是我应该处理它?<​​/ p>

1 个答案:

答案 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会因编译器而异。

在此处查看更多Concat an integer to a String - use String literal or primitive from performance and memory point of view?