博客已持续运行3675天
人们总是想离家越走越远却发现身后只剩家人...
进入博客
不要停下脚步哪怕前方没有光
2.15
2017
Day3 笔记 选择结构if语句格式3 练习
 
import java.util.Scanner;
class Test1_If {
	//练习:键盘录入一个成绩,判断并输出成绩的等级.
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
	/*
		System.out.println("小朋友,请输入您本期的语文成绩:");
		int x = sc.nextInt();
		if (x > 100) {
			System.out.println("三好学生");
		}else if (x >= 90 && x <= 100) {
			System.out.println("优");
		}else if (x >= 80 && x <= 89) {
			System.out.println("良");
		}else if (x >= 70 && x <= 79) {
			System.out.println("中");
		}else if (x > 60 && x <= 69) {
			System.out.println("及");
		}else if (x > 50 && x <= 59) {
			System.out.println("差");
		}else{
			System.out.println("对不起,您的成绩羞辱了电脑的智商");
		}
		System.out.println("--Rick 2017/02/15");
		*/
		

		//练习2:键盘录入x的值,计算出y的并输出
			/*
			x>=3        y = 2 * x + 1;
			-1<x<3        y = 2 * x;
			x<=-1        y = 2 * x - 1;
			*/
		System.out.println("请输入一个整数");
		int x = sc.nextInt();
		int y = 0;
		if (x >= 3) {
			y = 2 * x + 1;
		}else if (x > -1 && x < 3) {
			y = 2 * x;
		}else if (x <= -1) {
			y = 2 * x - 1;
		}
		System.out.println(y);
	}
}
上一篇
回到顶部
Powered by 顾羽宸. Written by . 浙icp备87656888号
在路上...     29.69ms