为什么printf的地方都提示错误
packagec02;//利用Scanner类声明的对象接收用户的输入。程序名:L02_10_ScannerInput.javaimportjava.util.Scann...
package c02;
//利用Scanner类声明的对象接收用户的输入。程序名:L02_10_ScannerInput.java
import java.util.Scanner;
public class L02_10_ScannerInput {
public static void main(String[] args) {
byte bVar; //声明字节型变量
int iVar; //声明整型变量
long lVar; //声明长整型变量
float fVar; //声明单精度型变量
double dVar;//声明双精度型变量
String str; //声明字符串型变量
Scanner sc=new Scanner(System.in);
System.out.print("请输入您的姓名:");
str=sc.next();
System.out.print("请输入一个字节型数据:");
bVar=sc.nextByte();
System.out.print("请输入一个整型数据:");
iVar=sc.nextInt();
System.out.print("请输入一个长整型数据:");
lVar=sc.nextLong();
System.out.print("请输入一个float型数据:");
fVar=sc.nextFloat();
System.out.print("请输入一个double型数据:");
dVar=sc.nextDouble();
System.out.println(str+"先生/女士,您好!您输入的数据如下:");
System.out.println("字符型数据:"+'a');
System.out.println(",字节型数据:"+bVar);
System.out.println(",整型数据:"+iVar);
System.out.println(",长整型数据:"+lVar);
System.out.println("单精度型数据:"+fVar);
System.out.println(",双精度型数据:"+dVar);
System.out.println("***************以下是格式化输出***************");
System.out.printf("布尔型:%5b\n",true);
System.out.printf("字符型:%c\n",'a');
System.out.printf("字节型:%3d%%\n",bVar);
System.out.printf("字符串:%6s\n",str);
System.out.printf("十进制:%7d\n",iVar);
System.out.printf("长整型:%15d\n",lVar);
System.out.printf("浮点数:%8.3f,双精度:%14.8f\n",fVar,dVar);
System.out.printf("浮点数:%8g,双精度:%14g\n",fVar,dVar);
System.out.printf("科学型:%9.2e,双精度:%9.2e\n",0.00432176,dVar);
System.out.println("***************以上是格式化输出***************");
System.out.println("感谢您使用本程序。");
}
}
错误为:
Multiple markers at this line
- The method printf(String, Object[]) in the type PrintStream is not applicable for the arguments (String,
boolean)
- The method printf(String, Object[]) in the type PrintStream is not applicable for the arguments (String,
Boolean)
诸如此类。求解 展开
//利用Scanner类声明的对象接收用户的输入。程序名:L02_10_ScannerInput.java
import java.util.Scanner;
public class L02_10_ScannerInput {
public static void main(String[] args) {
byte bVar; //声明字节型变量
int iVar; //声明整型变量
long lVar; //声明长整型变量
float fVar; //声明单精度型变量
double dVar;//声明双精度型变量
String str; //声明字符串型变量
Scanner sc=new Scanner(System.in);
System.out.print("请输入您的姓名:");
str=sc.next();
System.out.print("请输入一个字节型数据:");
bVar=sc.nextByte();
System.out.print("请输入一个整型数据:");
iVar=sc.nextInt();
System.out.print("请输入一个长整型数据:");
lVar=sc.nextLong();
System.out.print("请输入一个float型数据:");
fVar=sc.nextFloat();
System.out.print("请输入一个double型数据:");
dVar=sc.nextDouble();
System.out.println(str+"先生/女士,您好!您输入的数据如下:");
System.out.println("字符型数据:"+'a');
System.out.println(",字节型数据:"+bVar);
System.out.println(",整型数据:"+iVar);
System.out.println(",长整型数据:"+lVar);
System.out.println("单精度型数据:"+fVar);
System.out.println(",双精度型数据:"+dVar);
System.out.println("***************以下是格式化输出***************");
System.out.printf("布尔型:%5b\n",true);
System.out.printf("字符型:%c\n",'a');
System.out.printf("字节型:%3d%%\n",bVar);
System.out.printf("字符串:%6s\n",str);
System.out.printf("十进制:%7d\n",iVar);
System.out.printf("长整型:%15d\n",lVar);
System.out.printf("浮点数:%8.3f,双精度:%14.8f\n",fVar,dVar);
System.out.printf("浮点数:%8g,双精度:%14g\n",fVar,dVar);
System.out.printf("科学型:%9.2e,双精度:%9.2e\n",0.00432176,dVar);
System.out.println("***************以上是格式化输出***************");
System.out.println("感谢您使用本程序。");
}
}
错误为:
Multiple markers at this line
- The method printf(String, Object[]) in the type PrintStream is not applicable for the arguments (String,
boolean)
- The method printf(String, Object[]) in the type PrintStream is not applicable for the arguments (String,
Boolean)
诸如此类。求解 展开
展开全部
printf的第二个参数需要的是数组
System.out.printf("布尔型:%5b\n", new Object[] {true});
更多追问追答
追问
为什么还是出错,显示
Type mismatch: cannot convert from boolean to Object
求解
追答
你是哪个版本的jdk啊。。。
System.out.printf("布尔型:%5b\n", new Object[] {new Boolean(true)});
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询