package 判断数位;
import java.util.*;
public class A {
public static void main(String args[])throws Exception{
Scanner stdin=new Scanner(System.in);
int result=0;
System.out.println("请输入任意一个0到9999的数字");
class AAException extends Exception
{
String a;
AAException()
{
a="输入数据出错";
}
public String toString()
{
return a;
}
}
class BB
{
public int getnum(int i) throws AAException
{
if(i<0||i>9999)
{
AAException exception=new AAException();
throw exception;
}
if(i>=0&&i<=9)
System.out.print("一位数");
else if(i>=10&&i<=99)
System.out.print("两位数");
else if(i>=100&&i<=999)
System.out.print("三位数");
else if(i>=1000&&i<=9999)
System.out.print("四位数");
}
}
BB a=new BB();
try{
String s=stdin.nextLine();
double ii=Double.parseDouble(s);
int i=(int)ii;
result=a.getnum(i);
}
catch(AAException e)
{System.out.println(e.toString());
}
}
}
求大神帮忙看下,整了半天也没搞定0.0
你的getnum方法 定义的时候需要返回int ,但你的方法体里面没有return,报错了
其实这个地方不用返回
public void getnum(int i) throws AAException {在调用的时候,这样写
try {能给一个完整的程序么,最好运行过的,不懂啊!
追答AAException.还是用你自己的,我给你重写下A
class A {