java键盘输入一个int_java程序:从键盘输入一个整型数值,输出它的所有因子。...

importjava.io.*;publicclassPrintOut{publicstaticvoidmian(String[]args){Stringstring="";inti=0;System.out.println("输入忆个整型数字:");BufferedReaderin=newBufferedReader(...

import java.io.*;

public class PrintOut {

public static void mian(String[] args) {

String string = "";

int i=0;

System.out.println("输入忆个整型数字:");

BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

string = in.readLine();

char a[]=string.toCharArray();

for(i = 0;i<5;i++)

System.out.println(a[i]);

}

}

错误报告:

C:\Documents and Settings\Administrator\PrintOut.java:17: 未报告的异常 java.io.IOException;必须对其进行捕捉或声明以便抛出

string = in.readLine();

^

1 错误

Process completed.

如果能解释清楚或者写一个我能看懂的程序我再追加分数。谢谢各位!

谢谢大家的帮助。我改了一下程序,为什么系统会出现这样的信息。

程序:

public static void main(String[] args) {

String string = "";

int i=0;

System.out.println("输入一个整型数字:");

try{

BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

string = in.readLine();

}catch(IOException e){}

char a[]=string.toCharArray();

for(i = 0;i<50;i++)

System.out.println(a[i]);

}

}

我输入:123456789

系统输出:

1

2

3

4

5

6

7

8

9

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 9

at PrintOut.main(PrintOut.java:22)

这是怎么回事,有关系吗?

这次我追加15分。

展开

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值