纯新手救助一个JAVA书上列子运行报错的问题
packageasb;publicclassArith{publicstaticvoidmain(String[]args){floatnumber1=45.56f;in...
package asb;
public class Arith {
public static void main(String[]args){
float number1=45.56f;
int number2=152;
System.out.println("和为:",number1+number2);
System.out.println("差为:",(number1+number2));
System.out.println("积为:",number1*number2);
System.out.println("商为:",number1/number2);
}
}
这个代码运行报错:Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The method println(float) in the type PrintStream is not applicable for the arguments (String, float)
The method println(float) in the type PrintStream is not applicable for the arguments (String, float)
The method println(float) in the type PrintStream is not applicable for the arguments (String, float)
The method println(float) in the type PrintStream is not applicable for the arguments (String, float)
请问是哪里出错了呢 展开
public class Arith {
public static void main(String[]args){
float number1=45.56f;
int number2=152;
System.out.println("和为:",number1+number2);
System.out.println("差为:",(number1+number2));
System.out.println("积为:",number1*number2);
System.out.println("商为:",number1/number2);
}
}
这个代码运行报错:Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The method println(float) in the type PrintStream is not applicable for the arguments (String, float)
The method println(float) in the type PrintStream is not applicable for the arguments (String, float)
The method println(float) in the type PrintStream is not applicable for the arguments (String, float)
The method println(float) in the type PrintStream is not applicable for the arguments (String, float)
请问是哪里出错了呢 展开
3个回答
展开全部
把下面四句代码中的逗号改为号,System.out.println这个函数,参数如果是有几个的话,要用加号连接
System.out.println("和为:"+number1+number2);
System.out.println("差为:"+(number1+number2));
System.out.println("积为:"+number1*number2);
System.out.println("商为:"+number1/number2);
System.out.println("和为:"+number1+number2);
System.out.println("差为:"+(number1+number2));
System.out.println("积为:"+number1*number2);
System.out.println("商为:"+number1/number2);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
很明显的错误啊,字符串不能这样和数字连接,你把逗号去掉,换成+号就行了,有问题请追问,没问题请采纳
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
System.out.println("和为:",number1+number2);
要在打印信息内加入占位符
System.out.println("和为:{0}",number1+number2);
要在打印信息内加入占位符
System.out.println("和为:{0}",number1+number2);
追问
应该不是这个问题,改过之后连报错都没变化
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询