Weyu‘s blog

  • 首页
  • 代码
  • 作品
  • 学习
  • 折腾
  • 随笔
  • 关于博主
  • 时光映像
  • 我的网盘
  • 文章归档
  • 友情链接

Day3 笔记 选择结构if语句格式3 练习

  • admin
  • 2017-02-15
  • 0
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);
	}
}
© 2025 Weyu‘s blog
  • {{ item.name }}
  • {{ item.name }}