try to make it as simple as possible.....3Q
import java.util.Scanner;class Counter {
public int c;
Counter () {
c= 0;
}
public void reSets() {
c = 0;
}
public void getIncrement (int i) {
c+=i;
}
public void getDecrement (int i) {
c-=i;
}
public int getCounter() {
return c;
}
}
public class TestCounter {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String t = "I";
String f = "D";
System.out.println("Increment (I)) or Decrement (D))");
String choice = input.nextLine();
System.out.println("Enter a number");
Counter cc = new Counter();
if(choice.equals(t)) {
do {
cc.getIncrement(input.nextInt());
if (cc.getCounter() >= 40) {
cc.reSets();
System.out.println("The maxmum value is 40 (Reset to 0), continue!");
continue;
}
System.out.println("Counter :" + cc.getCounter());
} while (cc.getCounter() < 40);
} else {
do {
cc.getDecrement(input.nextInt());
if (cc.getCounter() <= -10) {
cc.reSets();
System.out.println("The minimun value is -10(ReSet to 0), continue");
continue;
}
System.out.println("Counter :" + cc.getCounter());
} while(cc.getCounter() > -10);
}
}
}
代码应该没问题吧,分成两个文件,后编译即可
Increment (I)) or Decrement (D))
I
Enter a number
10
Counter :10
30
The maxmum value is 40 (Reset to 0), continue!
34
Counter :34
45
The maxmum value is 40 (Reset to 0), continue!
java的类名和文件名必须是一致的 peterboboo 发表于 2013-10-30 14:02 static/image/common/back.gif
代码应该没问题吧,分成两个文件,后编译即可
Increment (I)) or Decrement (D))
I
代码没问题, wo hui 分成两个文件. 问题shi xiang ba ta jian huan.... 不懂jian huan 什么意思 ≮芸魡影耔≯ 发表于 2013-12-8 11:15 static/image/common/back.gif
不懂jian huan 什么意思
简化
simplify~:lol:
页:
[1]