1 . 自定义 表DAYS 及其方法dayInmonth( )。该方法的功能是返回用户输入的月份天数(2月份就换28天计算)。例如用户输入3,则该方法将返回值31;用户输入4,则该方法将返回值30。通过main()方法将返回值显示出来。
2. 自定义类Cla,该类中有方法convert(),其功能是将传入的数字字符串转换成数字,并显示出来。但若传入的字符串中含有字母,则将该方法能抛出NumberForma Exception异常,并输出“所输入的字符串中含有非数字的文字,无法转换”
1 . 自定义 表DAYS 及其方法dayInmonth( )。该方法的功能是返回用户输入的月份天数(2月份就换28天计算)。例如用户输入3,则该方法将返回值31;用户输入4,则该方法将返回值30。通过main()方法将返回值显示出来。
2. 自定义类Cla,该类中有方法convert(),其功能是将传入的数字字符串转换成数字,并显示出来。但若传入的字符串中含有字母,则将该方法能抛出NumberForma Exception异常,并输出“所输入的字符串中含有非数字的文字,无法转换”
//=============Q2=================== //even though i am not sure what should be returned if exception has occured //you might think about it yourself // :-) //and i m also not sure why to write a class here.. //a method will be well enough for doing this public class Cla{ public Cla(){}
public int convert(String s){ try{ return Integer.parseInt(s); }catch(NumberFormatException e){ System.out.println("Whatever message is"); } return -1; } }
//===============Q1================= public int dayInMonth(int month){ if (month == 1|month == 3|month == 5|month == 7|month == 8|month == 10|month == 12) return 31; else if (month == 2) return 28; else return 30; }