使用标记值控制循环:sum,data 电视 10.27

package com.baidu;
import java.util.Scanner;
public class SentinelValue           

               {        public static void main(String[] args)

                     {       Scanner input = new Scanner(System.in);//(Input):只能从中读取数据,而不能向其写入数据


                            System.out.print("Enter an unteger (the input ends if it is 0 ): ");
                            int data = input.nextInt();//(Input):只能从中读取数据,而不能向其写入数据

                           int sum = 0;
                           while(data != 0)

                         {   sum += data;

            System.out.print("Enter an integer (the input ends if it is 0): ");
            data = input.nextInt();//(Input):只能从中读取数据,而不能向其写入数据
                          }
           System.out.println("The sum is " + sum);
                  }
            }

 

 

 

 

 

 

public class SimpleCircle {
    private double radius;
    public SimpleCircle() {
        this.radius=1;
    }
    public SimpleCircle(double radius){
        this.radius=radius;
    }
    public double getArea() {
        // TODO Auto-generated method stub
        return Math.PI*radius*radius;
    }
    public double getPerimeter() {
        return 2*Math.PI*radius;
    }
    
    public static void main(String[] args) {
        SimpleCircle cir1=new SimpleCircle();
        System.out.println("The area of the circle of radius "+cir1.radius+" is "+cir1.getArea());
        SimpleCircle cir2=new SimpleCircle(10);
        System.out.println("The area of the circle of radius "+cir2.radius+" is "+cir2.getArea());
    }
}

public class TV {
    public int channel=1;
    public int volumeLevel=1;
    public boolean on=false;
    
    public TV() {
        
    }
    public void turnOn() {
        on =true;
        System.out.println("电视机已经打开了。");
    }
    public void turnOff() {
        on=false;
        System.out.println("电视机已经关闭了。");
    }
    public int getChannel() {
        return channel;
    }
    public void setChannel(int channel) {
        if(on) {
            System.out.println("电视机已开,可以开始调台了。");
            if(channel>=1&&channel<=120) {
                this.channel = channel;
                System.out.println("频道已经调到 "+channel+" 台");
            }else {
                System.out.println("你要调的频道不存在。");
            }
        }else {
            System.out.println("电视机关着的时候是不能调台的");
        }
    }
    public int getVolumeLevel() {
        return volumeLevel;
    }
    public void setVolumeLevel(int volumeLevel) {
        if(on) {
            System.out.println("电视机已开,声音大小可调了");
            if(volumeLevel>=1&&volumeLevel<=7) {
                this.volumeLevel = volumeLevel;
                System.out.println("声音的大小设置成了 "+volumeLevel+" 大小");
            }
        }else {
            System.out.println("电视机关着的时候是不能调声音的");
        }
        
    }
    public void channelUp() {
        if(on&&channel<120) {
            channel++;
        }
    }
    public void channelDown() {
        if(on&&channel>1) {
            channel--;
        }
    }
    public void volumeUp() {
        if(on&&volumeLevel<7) {
            volumeLevel++;
        }
    }
    public void volumeDown() {
        if(on&&volumeLevel>1) {
            volumeLevel--;
        }
    }
    
    
}
public class TestTV {
    public static void main(String[] args) {
      TV tv1=new TV();
      tv1.turnOn();
     tv1.setChannel(30);
      tv1.setVolumeLevel(3);
      
      TV tv2=new TV();
      tv2.turnOn();
      System.out.println("TV2's channel is "+tv2.channel+" and volume is "+tv2.volumeLevel);
      tv2.channelUp();
      System.out.println("TV2's channel is "+tv2.channel+" and volume is "+tv2.volumeLevel);
      tv2.channelUp();
      System.out.println("TV2's channel is "+tv2.channel+" and volume is "+tv2.volumeLevel);
      tv2.channelUp();
      System.out.println("TV2's channel is "+tv2.channel+" and volume is "+tv2.volumeLevel);
      tv2.volumeUp();
      System.out.println("TV2's channel is "+tv2.channel+" and volume is "+tv2.volumeLevel);
      tv2.volumeUp();
      System.out.println("TV2's channel is "+tv2.channel+" and volume is "+tv2.volumeLevel);
      tv2.volumeUp();
      System.out.println("TV2's channel is "+tv2.channel+" and volume is "+tv2.volumeLevel);
      
      
  }

}

 
 
 
 
 

 

转载于:https://www.cnblogs.com/jingjing1314/p/7825969.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值