Java不兼容类型 import java.io.*; 公共类redtry4{ 公共静态void main(字符串[]args)引发IOException{ BufferedReader IN=新的BufferedReader(新的InputStreamReader(System.IN)); 字符串[]numx=新字符串[10]; System.out.println(“输入10个不同的数字:”); for(int b=0;b
Java不兼容类型 import java.io.*; 公共类redtry4{ 公共静态void main(字符串[]args)引发IOException{ BufferedReader IN=新的BufferedReader(新的InputStreamReader(System.IN)); 字符串[]numx=新字符串[10]; System.out.println(“输入10个不同的数字:”); for(int b=0;b,java,Java,numx是一个字符串,Integer.parseInt(IN.readLine())的返回类型是一个int,因此出现错误 int[]numx = new int[10]; 将num数组更改为字符串数组 import java.io.*; public class redtry4 { public static void main(String[]args)throws IOException{ BufferedReader IN = new BufferedReader
numx
是一个字符串,Integer.parseInt(IN.readLine())
的返回类型是一个int,因此出现错误
int[]numx = new int[10];
将num数组更改为字符串数组
import java.io.*;
public class redtry4 {
public static void main(String[]args)throws IOException{
BufferedReader IN = new BufferedReader(new InputStreamReader(System.in));
String[]numx = new String[10];
System.out.println("Enter 10 different numbers:");
for(int b=0; b<10; b++)
{
System.out.println("Accepted numbers are:"+"\n"+b);
numx[b]=Integer.parseInt(IN.readLine());
}
}
}
int[]numx = new int[10];
或者不要使用Integer.parseInt
将值转换为整数
int[]numx = new int[10];
根据您的需要,您可以选择。更改
int[]numx = new int[10];
numx[b]=IN.readLine();
到
int[]numx = new int[10];
如果要将输入解析为整数,请将它们存储在整数数组中。
如果你仍然想把它们存储在一个字符串数组中,不要调用<代码> PARSETIN < /COD>。你也可以考虑使用<代码>扫描器< /C> >从控制台读取输入;
int[]numx = new int[10];