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;
}
}
}
}