这是第一个的1解,欢迎批评斧正。小弟初学java。gg们多多指点。谢谢大家
五位数字是可配置的,不是读取的。
public class JudgeOddEven {
private static int WUWEISHUZI = 54321;
private static int i;
private static int g;
private static int gs;
private static int s;
private static int gsb;
private static int b;
private static int gsbq;
private static int q;
private static int w;
private static int countOdd = 0;
private static int countEven = 0;
private JudgeOddEven(){
}
private void business(){
i = WUWEISHUZI;
g = i%10;
System.out.println("***g = " + g);
gs = i%100;
s = (gs - g)/10;
System.out.println("***s = " + s);
gsb = i%1000;
b = (gsb - gs)/100;
System.out.println("***b = " + b);
gsbq = i%10000;
q = (gsbq - gsb)/1000;
System.out.println("***q = " + q);
w = (i - gsbq)/10000;
System.out.println("***w = " + w);
}
private void process(int j){
if ( j == 2){
System.out.println("******" + j + "is an Even.");
countEven ++;
}else if ( j > 2 && j % 2 == 0){
System.out.println("******" + j + "is an Even.");
countEven ++;
}else{
System.out.println("******" + j + "is an Odd.");
countOdd ++;
}
}
private int result(){
int p = g + s + b + q + w;
return p;
}
private void display(){
business();
process(g);
process(s);
process(b);
process(q);
process(w);
System.out.println("The sum of the five figure is: " + result());
System.out.println("The Number of Odd is: " + countOdd);
System.out.println("The Number of Even is: " + countEven);
}
/**
* @param args
*/
public static void main(String[] args) {
JudgeOddEven j = new JudgeOddEven();
j.display();
}
}