这是我的代码:
import java.io.*;
public class Main {
public static void main(String[] args) throws Exception {
BufferedReader b = new BufferedReader(new InputStreamReader(System.in));
String s = b.readLine();
for (int i = 0; i < s.length(); i++)
{
if (i % 2 == 0) {
int a = Integer.parseInt(String.valueOf(s.charAt(i)));
System.out.print(a);
}
}
}
}
这段代码适用于一位数的整数,但如果输入是两位数,那么它就会一团糟。
我的输入:1 3 6 5 7 输出:1 3 6 5 7 效果很好,但是,如果输入是:1 3 66 58 7 输出:发生异常。如何处理这样的两位整数输入。
白猪掌柜的
相关分类