Java 学习日记Day6

1.0 三个和尚案例

package HeiMa;
/*
 * 三个和尚案例
 * 给定150,210,165判断最高的身高
 * 三目运算符
 */
public class Day1_1 {
	public static void main(String []args) {
		int high1 = 150;
		int high2 = 210;
		int high3 = 165;
		int a = high1 > high2 ? high1 : high2;
		int b = a > high3 ? a : high3; 
		System.out.println("身高最高的是"+ b);
	}
}

2.0三个和尚比身高升级版,自己设置身高

import java.util.Scanner;
public class Day1_2 {
	public static void main(String []args) {
		//导包
		Scanner sc = new Scanner(System.in);
		//输入三个身高
		System.out.println("请输入第一个和尚的身高");
		int high1 = sc.nextInt();
		System.out.println("请输入第二个和尚的身高");
		int high2 = sc.nextInt();
		System.out.println("请输入第三个和尚的身高");
		int high3 = sc.nextInt();
		int a = high1 > high2 ? high1 : high2;
		int b = a > high3 ? a : high3; 
		System.out.println("身高最高的是"+ b);
	}
}

4.0判断奇偶数

package HeiMa;
/*
 * 判断奇偶数
 * 练习if else
 */
import java.util.Scanner;
public class Day1_3 {
	public static void main(String []args) {
		Scanner sc = new Scanner(System.in);
		System.out.println("请输入一个数字:");
		int a = sc.nextInt();
		if(a%2 == 0) {
			System.out.println("a是偶数");
		}else {
			System.out.println("a是奇数");
		}
	}
}

5.0判断月份

package HeiMa;
/*
 * 判断月份
 * switch语句的实践
 * case的穿透
 */
import java.util.Scanner;
public class Day1_5 {
	public static void main(String []args) {
		Scanner sc = new Scanner(System.in);
		System.out.println("请输入月份");
		int number = sc.nextInt();
		switch(number) {
		case 3:
		case 4:
		case 5:
			System.out.println("春季");
		break;
		case 6:
		case 7:
		case 8:
			System.out.println("春季");
		break;
		case 9:
		case 10:
		case 11:
			System.out.println("春季");
		break;
		case 12:
		case 1:
		case 2:
			System.out.println("春季");
		break;
		default:
			System.out.println("您输入的有误");
		}
	}
}

7.0判断奇偶数

package HeiMa;
/*
 * 求偶数和
 */
public class Day1_7 {
	public static void main(String []args) {
		int sum = 0;
		for(int i = 1;i<100;i++) {
			if(i%2 == 0) {
				sum += i;
			}
		}
		System.out.println("和为:" + sum);
	}
}

8.0水仙花数

package HeiMa;
/*
 * 1.0输出所有的水仙花数
 * 2.0统计水仙花数的个数
 */
public class Day1_8 {
 public static void main(String []args) {
	 int number = 0;
	 for(int i = 100;i < 1000;i++) {
		 int high = i/100;
		 int temp = i/10%10;
		 int low = i%10;
		 if(high*high*high + temp*temp*temp + low*low*low == i) {
			 number++;
			 System.out.println(i);
		 }
	 }
	 System.out.println("水仙花的个数是" + number);
 }
}

9.0猜数字

package HeiMa;
/*
 * 猜数字1-100
 */
import java.util.Random;
import java.util.Scanner;
public class Day1_10 {
	public static void main(String []args) {
		Random r = new Random();
		int number = r.nextInt(100);
		while(true) {
		System.out.println("请输入您猜的数字");
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		if(x < number) {
			System.out.println("您猜小了");
		}else if(x > number) {
			System.out.println("您猜大了");
		}else {
			System.out.println("恭喜您!您猜对了");
			break;
		}
		}
	}
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值