java程序出现Exception in thread "main"是什么问题?
程序要求输入姓名。分别输出姓和名。如输入leedu。输出fistname:leelastname:duimportjava.util.Scanner;publicclas...
程序要求输入姓名。分别输出姓和名。如输入lee du。输出fist name: lee last name:du
import java.util.Scanner;
public class Program7 {
public static void main(String[] args) {
int i,j;
System.out.print("请随便输入姓名:");
Scanner in=new Scanner(System.in);
String name=in.nextLine();
int n=name.length();
char[] ch=name.toCharArray();
for(i=0;i<n;i++);
{
char c=ch[i];
if(c!=' ')
System.out.println(ch[i]);
else
j=i+1;
for(j=i+1;j<n;j++);
{
System.out.println(ch[j]);
}
}
}
}
出错提示:Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 展开
import java.util.Scanner;
public class Program7 {
public static void main(String[] args) {
int i,j;
System.out.print("请随便输入姓名:");
Scanner in=new Scanner(System.in);
String name=in.nextLine();
int n=name.length();
char[] ch=name.toCharArray();
for(i=0;i<n;i++);
{
char c=ch[i];
if(c!=' ')
System.out.println(ch[i]);
else
j=i+1;
for(j=i+1;j<n;j++);
{
System.out.println(ch[j]);
}
}
}
}
出错提示:Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询