62,623
社区成员
发帖
与我相关
我的任务
分享 String s="";
ArrayList list=new ArrayList();
int sign=1;//输入不是数字字符串是的异常标志,1为异常
while(s!=null)
{
while(sign==1)
{
try
{
//这里得到你输入的字符串的代码,不知道你字符串怎么传进来的
sign=0;
if(s!=null)
{
int a=Integer.parseInt(s);
}
}
catch(NumberFormatException e)
{
sign=1;
}
}
if(s!=null)
list.add(s);
}
int len=list.size();
int ch[]=new int[len];
for(int i=0;i<len;i++)
{
String tempStr=(String)list.get(i);
int tempInt=Integer.parseInt(tempStr);
ch[i]=tempInt;
}
try{
byte[] b = new byte[1024];
int n = System.in.read(b);
//去掉回车和换行
String s = new String(b,0,n);
//分割字符串
String[] str = s.plit("");
//转换成数字
int[] num = new int[str.length];
for(int i = 0;i < num.length;i++){
num[i] = Integer.parseInt(str[i]);
}
}
System.out.print("Pls input your number around spaces:");
BufferedReader br = new BufferedReader(new InputStreamReader(
System.in));
String st = (String) br.readLine();
String[] result = st.split("\\s+");
int[] last = new int[result.length];
for (int i=0;i<result.length;i++) {
last[i] = Integer.parseInt(result[i]);
}