鱼C论坛

 找回密码
 立即注册
查看: 3775|回复: 4

try to make it as simple as possible.....3Q

[复制链接]
发表于 2013-10-30 07:53:58 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
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);

        }  
    }        
}     

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2013-10-30 14:02:08 | 显示全部楼层
代码应该没问题吧,分成两个文件,后编译即可
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的类名和文件名必须是一致的
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-10-30 23:04:17 | 显示全部楼层

代码没问题, wo hui 分成两个文件. 问题shi xiang ba ta jian huan....
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2013-12-8 11:15:02 | 显示全部楼层
不懂jian huan 什么意思
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2014-1-26 15:43:17 | 显示全部楼层
≮芸魡影耔≯ 发表于 2013-12-8 11:15
不懂jian huan 什么意思

简化
simplify~:lol:
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-24 22:01

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表