要求:m定义为类的属性,需定义构造函数为m赋值;当m大于99999时,输出错误信息“the number is too large”,不再执行。
public class T { private int m; public T(int m) { super(); this.m = m; } public int getM() { return m; } public void setM(int m) { this.m = m; } public void M() { if(m>99999) { System.out.println("the number is too large"); } else { String str=m+""; System.out.println("一共有"+str.length()+"位"); System.out.println("每位数字是:"); for(int i=0;i<str.length();i++) { System.out.print(str.charAt(i)+" "); } System.out.println(" 逆序"); for(int i=str.length()-1;i>=0;i--) { System.out.print(str.charAt(i)); } } } public static void main(String[] args) { T m=new T(85412); m.M(); } }