一个关于throws的问题
import java.io.*;//import java.io.BufferedReader;
//import java.io.InputStreamReader;
//import java.io.IOException;
class Inputs
{
public int inputed() throws IOException
{
BufferedReader Mo=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Please input a num:");
System.out.flush();
String num1=Mo.readLine();
int x=Integer.parseInt(num1);
return x;
}
public int inputeds() throws IOException
{
BufferedReader Mo=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Please input another num:");
System.out.flush();
String num2=Mo.readLine();
int y=Integer.parseInt(num2);
return y;
}
}
class Maths extends Inputs
{
public void add(int x,int y)
{
System.out.println("The answer is"+(x+y));
}
public void volume(int x,int y)
{
System.out.println("The answer is"+(x*y));
}
public void reduce(int x,int y)
{
System.out.println("The answer is"+(x-y));
}
public void remove(int x,int y)
{
System.out.println("The answer is"+(x/y));
}
public void rise(int x)
{
System.out.println("The answer is "+(x*x));
}
public static void main(String[] args) throws IOException
{
Maths Mor=new Maths();
Inputs Mod= new Inputs();
System.out.println("Introduction:1 代表 “+“;2 代表 “-“;3 代表 “*“;4 代表 “/“");
System.out.println("5 代代表 “乘方“");
System.out.print("Please choose the math sub:");
BufferedReader Mo=new BufferedReader(new InputStreamReader(System.in));
System.out.flush();
String mathsub=Mo.readLine();
int m=Integer.parseInt(mathsub);
System.out.println("You Choosed The "+mathsub);
int x=Mod.inputed();
int y=Mod.inputeds();
switch(m)
{
case 1:
Mor.add(x,y);
break;
case 2:
Mor.reduce(x,y);
break;
case 3:
Mor.volume(x,y);
break;
case 4:
Mor.remove(x,y);
break;
case 5:
Mor.rise(x);
break;
default:System.out.println("Your Choose is Wrong");
}
}
}
这是我照别人的敲的一个程序 但是其中有点不懂那就是 public int inputed() throws IOException ;public int inputeds() throws IOException; public static void main(String[] args) throws IOException;这几个为什么在后面一定要throws IOException 这个东西 这个东西有什么用`