| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 521 人关注过本帖
标题:一个关于throws的问题
只看楼主 加入收藏
shiyide
Rank: 2
等 级:新手上路
威 望:4
帖 子:297
专家分:0
注 册:2006-2-22
收藏
 问题点数:0 回复次数:2 
一个关于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 这个东西 这个东西有什么用`
搜索更多相关主题的帖子: throws 
2006-05-09 22:20
wujiang
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2006-4-10
收藏
得分:0 
这是说明这些方法内可能产生各种异常,而且在方法体内不作处理,调用该方法的时候再进行处理
2006-05-09 22:40
lll423
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2006-4-19
收藏
得分:0 
IOException 当发生某种 I/O 异常时,抛出此异常。此类为异常的通用类,它是由失败的或中断的 I/O 操作生成的
2006-05-10 11:37
快速回复:一个关于throws的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013932 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved