package untitled4;import java.io.*;public class Untitled1 { public static void main(String[] args) { int a,b; char c; System.out.println("input number+char+number:"); a=(int)System.in.read(); c=(char)System.in.read(); b=(int)System.in.read(); switch(c) { case'+':System.out.println(a+b);break; case'-':System.out.println(a-b);break; case'*':System.out.println(a*b);break; case'/':System.out.println(a/b);break; } } } "Untitled1.java": Error #: 360 : unreported exception: java.io.IOException; must be caught or declared to be thrown at line 10, column 21 "Untitled1.java": Error #: 360 : unreported exception: java.io.IOException; must be caught or declared to be thrown at line 11, column 22 "Untitled1.java": Error #: 360 : unreported exception: java.io.IOException; must be caught or declared to be thrown at line 12, column 21
public static void main(String[] args) {
int a,b;
char c;
System.out.println("input number+char+number:");
a=(int)System.in.read();
c=(char)System.in.read();
b=(int)System.in.read();
switch(c)
{
case'+':System.out.println(a+b);break;
case'-':System.out.println(a-b);break;
case'*':System.out.println(a*b);break;
case'/':System.out.println(a/b);break;
}
}
}
"Untitled1.java": Error #: 360 : unreported exception: java.io.IOException; must be caught or declared to be thrown at line 10, column 21
"Untitled1.java": Error #: 360 : unreported exception: java.io.IOException; must be caught or declared to be thrown at line 11, column 22
"Untitled1.java": Error #: 360 : unreported exception: java.io.IOException; must be caught or declared to be thrown at line 12, column 21
public static void main(String[] args) throws IOException{
int a,b;
char c;
System.out.println("input number+char+number:");
a=(int)System.in.read();
c=(char)System.in.read();
b=(int)System.in.read();
switch(c)
{
case'+':System.out.println(a+b);break;
case'-':System.out.println(a-b);break;
case'*':System.out.println(a*b);break;
case'/':System.out.println(a/b);break;
}
}
}
就可以了
public static void main(String[] args) throws IOException{
int a,b;
char c;
System.out.println("input number+char+number:");
a=(int)System.in.read();
c=(char)System.in.read();
b=(int)System.in.read();
switch(c)
{
case'+':System.out.println(a+b);break;
case'-':System.out.println(a-b);break;
case'*':System.out.println(a*b);break;
case'/':System.out.println(a/b);break;
}
}
}
java.lang.NoClassDefFoundError: junit/textui/TestRunnerException in thread "main"
public static void main(String[] args) throws IOException{
int a,b;
char c;
System.out.println("input number+char+number:");
a=(int)System.in.read();
c=(char)System.in.read();
b=(int)System.in.read();
switch(c)
{
case'+':System.out.println(a+b);break;
case'-':System.out.println(a-b);break;
case'*':System.out.println(a*b);break;
case'/':System.out.println(a/b);break;
}
}
}