/** * @Author 小田不喝汤 * @Date 2024/1/23 */ public class AddDemo01 { public static void main(String[] args) { int a = 3; int b = a++; System.out.println("b = "+b); int c= ++a; System.out.println("c = "+c); } }
/** * @Author 小田不喝汤 * @Date 2024/1/23 */ public class ArithmaticDemo03 { public static void main(String[] args) { //加减乘除取余 int a = 3; int b =5; System.out.println(a+b); System.out.println(b-a); System.out.println(a*b); System.out.println(b/a); System.out.println(b%a); } }
/** * @Author 小田不喝汤 * @Date 2024/1/23 */ import java.util.Scanner; public class Distance { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("请输入下落时间:"); int t = sc.nextInt(); double s = 0.5*9.8*t*t; System.out.println("下落位移为:"+s); } }
/** * @Author 小田不喝汤 * @Date 2024/1/23 */ public class DoubleForDemo01 { public static void main(String[] args) { for (int i = 1;i <= 9; i++){ for (int j = 1;j <= i;j++){ System.out.print( " "+i+"*"+j+"="+(i*j)); } System.out.println(); } } }
/** * @Author 小田不喝汤 * @Descrip * do-while语句的应用 * @Date 2024/1/23 */ public class DoWhileDemo { public static void main(String[] args) { int i = 500; do { System.out.println(i + " "); i++; }while (i <= 0); } }
/** * @Author 小田不喝汤 * @Descrip * for语句的应用 * @Date 2024/1/23 */ public class ForDemo { public static void main(String[] args) { //打印 1-10以内的数字 for (int i = 1; i<= 10;i++) {if (i==5){ continue; } System.out.print(i + " "); } //打印 1—100的偶数 System.out.println(" "); for (int n = 1; n <=100;n++){ if (n%2==0){ System.out.print(n + " "); } } } }
/** * @Author 小田不喝汤 * @Date 2024/1/23 */ //提示用户输入姓名和年龄 import java.util.Scanner; public class IdentifyDemo01 { public static void main(String[] args) { //键盘扫描器 表示创建一个Scanner 类型的引用(Scanner) 指向Scanner 类型的对象,其中System.in可以看成是一个键盘输入 Scanner scanner = new Scanner(System.in); //提示用户输入姓名 System.out.println("请输入你的姓名:"); String name = scanner.next(); //提示用户输入年龄 System.out.println("请输入你的年龄:"); int age = scanner.nextInt(); System.out.println("我叫"+name +",今年"+age+"岁了"); } }
/** * @Author 小田不喝汤 * @Date 2024/1/23 */ import java.util.Scanner; public class IdentifyDemo02 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("请输入学号:"); String Number = scanner.next(); System.out.println("请输入班级:"); int ClassNumber = scanner.nextInt(); System.out.println("请输入座右铭:"); String Str = scanner.next(); System.out.println("学号:"+Number+",班级:"+ClassNumber+",我的座右铭是:"+Str); } }
/** * @Author 小田不喝汤 * @Date 2024/1/23 */ public class IfDemo01 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("请输入你的年龄:"); int age = sc.nextInt(); if(age >=18) { System.out.println("你可以浏览此网站!"); } else { int a = 18 - age; System.out.println("啧啧啧,小朋友再练"+a+"年吧!"); } } }
import java.util.Scanner; /** * @Author 小田不喝汤 * @Date 2024/1/23 */ public class IfDemo02 { public static void main(String[] args) { Scanner sc =new Scanner(System.in); System.out.println("请输入两个不同的正数:"); int num1 = sc.nextInt(); int num2 = sc.nextInt(); /*if(num1 >num2) { System.out.println("最大数为"+num1); } if(num1 <num2) { System.out.println("最大数为"+num2); } else { System.out.println("你输入的数相同!"); }*/ int max = num1; if(num1 <= num2) { max = num2; } System.out.println("最大值:"+max); } }
/** * @Author 小田不喝汤 * @Descrip:使用if-else分支结构 * @Date 2024/1/23 */ import java.util.Scanner; public class IfElseDemo { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("请输入的成绩:"); double score = sc.nextDouble(); if (score >= 60) { System.out.println("恭喜你,没挂课,可以过好年了!"); } else { System.out.println("恭喜你,小菜鸡,去补考吧!!!"); } } }
/** * @Author 小田不喝汤 * @Date 2024/1/23 */ import java.util.Scanner; public class IfElseIfElseDemo01 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("请输入你的身份信息:(军人、学生、普通人)"); String identify = sc.next(); //对用户输入的身份信息进行判断 if("军人".equals(identify)){ System.out.println("由于您是军人,享受免票"); }else if("学生".equals(identify)) { System.out.println("由于您是学生,享受半价票"); } else { System.out.println("抱歉,您没有任何优惠!"); } } }
/** * @Author 小田不喝汤 * @Descrip * switch语句的应用 * @Date 2024/1/23 */ import java.util.Scanner; public class Month { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("请输入月份:"); int month = sc.nextInt(); switch (month){ case 1: case 3: case 5: case 7: case 8: case 10: case 12: System.out.println("31天"); break; case 2: System.out.println("29天"); break; case 4: case 6: case 9: case 11: System.out.println("30天"); break; default: System.out.println("输入错误!!!"); } } }
/** * @Author 小田不喝汤 * @Date 2024/1/23 */ import java.util.Scanner; public class School { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("请输入您的高考成绩:"); int score = sc.nextInt(); if (score > 650){ System.out.println("c9联盟!"); } else if(score > 550&&score <650) { System.out.println("985、211!"); } else if (score > 450&&score <550) { System.out.println("一本!"); } else if (score > 350&&score < 450) { System.out.println("二本!"); } else{ System.out.println("补习一下吧!"); } } }
/** * @Author 小田不喝汤 * @Descrip * switch语句的应用 * @Date 2024/1/23 */ import java.util.Scanner; public class SwitchCaseDemo { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("请输入你的业绩名次"); int num = sc.nextInt(); switch (num){ case 1: System.out.println("欧洲游"); break; case 2: System.out.println("亚洲游"); break; case 3: System.out.println("国内游"); break; case 4: System.out.println("省内游"); break; default: System.out.println("加班!!!"); } } }
import sun.security.krb5.SCDynamicStoreConfig; import java.util.Scanner; /** * @Author 小田不喝汤 * @Description: * 使用三目运算符判断用户输入的整数是负数、正数还是零 * 提示用户输入一个三位数的正数,然后逆序处理在打印输出 * @Date 2024/1/23 */ public class ThreeEyesdemo { public static void main(String[] args) { //提示用户输入一个数 Scanner sc = new Scanner(System.in); System.out.println("请输入一个数:"); int number = sc.nextInt(); //使用三目运算符对用户输入的数进行判断 String s = number > 0 ? "你输入的是一个正数":number == 0 ? "你输入的是0" : "你输入的是一个负数"; System.out.println(s); if (number > 99&&number < 1000) { int a = number%100%10; int b = number/10%10; int c = number/100; int number1 = a*100+b*10+c; System.out.println("逆序为" + number1); } } }
import java.util.Scanner; /** * @Author 小田不喝汤 * @Descrip * while语句的应用 * @Date 2024/1/23 */ public class WhileDemo01 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int i = 0; while (true){ System.out.println("你已经跑了第"+i+"圈"); System.out.println("还跑不跑?"); System.out.println("请输入跑还是不跑!!!"); String str = sc.next(); if ("跑".equals(str)){ System.out.println("加油,加油!正在跑!!!");i++; } if ("不跑".equals(str)){ System.out.println("小子,这就跑不动了???给我练!!!"); } } } }