您当前的位置: 首页 >  Java

星夜孤帆

暂无认证

  • 5浏览

    0关注

    626博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Java学习笔记(6)-条件语句

星夜孤帆 发布时间:2018-05-20 17:54:59 ,浏览量:5

package day03;
/*
 * if语句
 */
public class Demo11 {
	public static void main(String[] args) {
		int a = 23;
		int b = 21;
		int c = 123;
		if(a>b){
			if(b>c){
				System.out.println("c最小:"+c);
			}else{
				System.out.println("b最小:"+b);
			}
		}else{
			if(a>c){
				System.out.println("c最小:"+c);
			}else{
				System.out.println("a最小:"+a);
			}
		}
	}
}
package day03;
import java.util.Scanner;
/*
 * 根据分数计算 级别
 * if else 多路分支
 */
public class Demo12 {
	public static void main(String[] args) {
		Scanner console = new Scanner(System.in);
		System.out.println("输入分数: ");
		int score = console.nextInt();
		if(score>=90){
			System.out.println("优秀");
		}else if(score>=80){
			System.out.println("良好");
		}else if(score>=70){
			System.out.println("中等");
		}else{
			System.out.println("差");
		}
	}
}

package day03;
/*
 * 请选择如下功能:
 * 1 显示全部用户列表
 * 2 添加新用户
 * 3 修改用户的密码
 * 4 删除已经存在的用户
 * 0 离开系统
 * 请选择(0,1,2,3,4)
 */
import java.util.Scanner;
public class Demo15 {
	public static void main(String[] args) {
		Scanner console = new Scanner(System.in);
		System.out.println("\t1 请选择如下功能: ");
		System.out.println("\t2 显示全部用户列表 ");
		System.out.println("\t3 添加新用户 ");
		System.out.println("\t4 修改用户的密码 ");
		System.out.println("\t5 删除已经存在的用户 ");
		System.out.println("\t0 离开系统");
		System.out.println("请选择(0,1):");
		int command = console.nextInt();
		switch(command){
		case 0:
			System.out.println("离开系统命令");
		break;
		case 1:
			System.out.println("显示全部命令");
		break;
		}
		
	}
}
package day03;
import java.util.Scanner;
/*
 * switch-case语句
 * 只能处理整数(byte,short,char,int)逻辑判断
 */
public class Demo14 {
	public static void main(String[] args) {
		Scanner console = new Scanner(System.in);
		System.out.println("输入分数:");
		int score = console.nextInt();
		switch(score/10){//整数
		case 10:
		case 9:
			System.out.println("优秀");
			break;//break打断
		case 8:
			System.out.println("良好");
			break;
		case 7:
			System.out.println("中等");
			break;
		default:
			System.out.println("差");
		}
	}
}

关注
打赏
1636984416
查看更多评论
立即登录/注册

微信扫码登录

0.0406s