Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/378.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java System.out.format问题,%d%n_Java - Fatal编程技术网

Java System.out.format问题,%d%n

Java System.out.format问题,%d%n,java,Java,它总是给我一个错误。 我对%d%n部分感到困惑。谁能给我解释一下吗?? 我希望钱的数量能显示出来。 多谢各位 System.out.println("Thank you for choosing withdrawl."); System.out.println("How much would u like to withdrawl?"); System.out.println("1=100"); System.out.println("2=200"); System.out.println("3

它总是给我一个错误。 我对%d%n部分感到困惑。谁能给我解释一下吗?? 我希望钱的数量能显示出来。 多谢各位

System.out.println("Thank you for choosing withdrawl.");
System.out.println("How much would u like to withdrawl?");
System.out.println("1=100");
System.out.println("2=200");
System.out.println("3=300");
System.out.println("4=400");
System.out.println("5=500");
withdrawlmoney = user.nextInt();
switch(withdrawlmoney){
    case 1:  withdrawlmoneynumber = "100";
        break;
    case 2:  withdrawlmoneynumber = "200";
        break;
    case 3:  withdrawlmoneynumber = "300";
        break;
    case 4:  withdrawlmoneynumber = "400";
        break;
    case 5:  withdrawlmoneynumber = "500";
        break;
    default: withdrawlmoneynumber = "Invalid amount";
        break;
}
System.out.println(withdrawlmoneynumber);
System.out.format("the value you want to withdrawl is: %d%n" , withdrawlmoneynumber);
更简单的方法:

System.out.println("The value you want to withdrawl is: " + withdrawlmoneynumber);
这适用于任何数据类型。

格式代码
“%d”
表示打印十进制数。但是您正在传递一个
字符串。
DrawalMoneyNumber
的数据类型应为数字

格式代码
“%n”
表示打印行分隔符,这取决于平台。它可能是
“\n”
“\r\n”
,或
“\r”
,具体取决于代码运行的位置。

请尝试

 System.out.format("the value you want to withdrawl is: %s\n" , withdrawlmoneynumber);
DrumblMoneyNumber是字符串

格式应为%s

根据


我猜您的意思是%n将\n表示新行

当我编译代码时,它不会给我错误。但当我运行它时,会弹出奇怪的消息,但它仍然不起作用。它表示java.util.IllegalFormatConversionExeption;d!=撇开java.lang.stringAn不谈,在纯文本字符串中:“要提取的值”-删除“提取”末尾的“l”-这是动词形式。并将所有的“撤回”改为“撤回”。如果您指定如何使用字符串,这将非常有用。我在下面的回答中有