当前位置: 技术问答>java相关
请高手帮我看一看错误在哪里!加10分!
来源: 互联网 发布时间:2015-01-07
本文导语: class SwitchTest2 { public static void main(String args[]) { int NumberOfWhite=0; int NumberOfDigits=0; int NumberOfOthers=0; char ch; while((ch=(char)System.in.read())!=-1&&ch!='n') { switch(ch) ...
class SwitchTest2
{
public static void main(String args[])
{
int NumberOfWhite=0;
int NumberOfDigits=0;
int NumberOfOthers=0;
char ch;
while((ch=(char)System.in.read())!=-1&&ch!='n')
{
switch(ch)
{
case'0':
case'1':
case'2':
case'3':
case'4':
case'5':
case'6':
case'7':
case'9': NumberOfDigits++;
break;
case' ':
case'n':
case't': NumberOfWhite++;
break;
}
}
System.out.println("nThe results as follow:n");
System.out.println("nNumber of digits=n"+NumberOfDigits+'n');
System.out.println("nNumber of white space=n"+NumberOfWhite+'n');
System.out.println("nNumber of others=n"+NumberOfOthers+'n');
}
}
{
public static void main(String args[])
{
int NumberOfWhite=0;
int NumberOfDigits=0;
int NumberOfOthers=0;
char ch;
while((ch=(char)System.in.read())!=-1&&ch!='n')
{
switch(ch)
{
case'0':
case'1':
case'2':
case'3':
case'4':
case'5':
case'6':
case'7':
case'9': NumberOfDigits++;
break;
case' ':
case'n':
case't': NumberOfWhite++;
break;
}
}
System.out.println("nThe results as follow:n");
System.out.println("nNumber of digits=n"+NumberOfDigits+'n');
System.out.println("nNumber of white space=n"+NumberOfWhite+'n');
System.out.println("nNumber of others=n"+NumberOfOthers+'n');
}
}
|
没有捕获异常而已
try{
你的程序
}
catch(java.io.IOException e){}
}
try{
你的程序
}
catch(java.io.IOException e){}
}