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);
}
}
import java.util.Scanner;
public class ThreeEyesDemo {
public static void main(String[] args){
//提示用户输入一个数
Scanner scanner = new Scanner(System.in);
System.out.println("请输入一个数:");
int number = scanner.nextInt();
//使用三目运算符对用户输入的数进行判断
String s =number >0 ? "你输入的是一个正数" :number ==0? "你输入的是0" :"你输入的是一个负数";
System.out.println(s);
}
}
import java.util.Scanner;
public class IfDemo01 {
public static void main(String[] args){
//提示用户输入两个数,求最大值
Scanner sc = new Scanner(System.in);
System.out.println("请输入第一个数");
int a = sc.nextInt();
System.out.println("请输入第二个数");
int b = sc.nextInt();
//判断求最大值,定义中间量
int max = a;
if(a < b){
max = b;
}
System.out.println("最大值:" + max);
}
import java.util.Scanner;
public class IfElseDemo {
public static void main(String[]args){
Scanner scanner = new Scanner(System.in);
System.out.println("请输入一个整数");
int a = scanner.nextInt();
if(a < 0){
System.out.println("你输入的是一个负数");
}
else{
System.out.println("你输入的是一个非负数");
}
}
}
import java.util.Scanner;
public class IfElseIfElseDemo {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入你的高考成绩");
double a = scanner.nextDouble();
if (a >= 650) {
System.out.println("上中北");
}else if(a >= 550){
System.out.println("上清华");
}else if(a >= 450){
System.out.println("上北大");
}else if(a >= 350){
System.out.println("上技校");
}else{
System.out.println("就这吧");
}
}
}
import java.util.Scanner; public class demo02 { public static void main(String[]args){ Scanner scanner = new Scanner(System.in); System.out.println("请输入你的学号"); String id=scanner.next(); System.out.println("请输入你的班级"); int classid = scanner.nextInt(); System.out.println("请输入你的座右铭"); String word=scanner.next(); System.out.println("我的学号是"+id+",班级是"+classid+",座右铭是"+word); } }
import java.util.Scanner; public class demo03 { public static void main(String []args){ Scanner scanner= new Scanner(System.in); int t=scanner.nextInt();; double x; x=0.5*9.8*t*t; System.out.println(x); } }
public class demo04 { 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); } }
public class demo05 { 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); } }
10、
import java.util.Scanner; public class demo06 { public static void main(String[]args){ Scanner scanner=new Scanner(System.in); int a=scanner.nextInt(); int b=scanner.nextInt(); if(a<b){ System.out.println(b); }if(a==b){ System.out.println("两个数一样大"); }else{ System.out.println(a); } } }
11、
public class Fordemo { public static void main(String[]args){ for (int i=1;i<=100;i++){ if(i%2==0){ System.out.print(i+" "); } } } }
12、
import java.util.Scanner; public class identifyDemo01 { public static void main(String[]args){ 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+"岁了!"); } }
13、
public class MultiplicationTable { public static void main(String[] args) { int n = 9; for (int i = 1; i <= n; i++) { for (int j = 1; j <= i; j++) { int result = i * j; System.out.print(j + " * " + i + " = " + result + "\t"); } System.out.println(); } } }
14、
import java.util.Scanner; public class RunDemo { public static void main(String[]args){ Scanner sc=new Scanner(System.in); int i=1; while(true){ System.out.println("你已经跑了第"+i+"圈,是否继续"); String str=sc.next(); if("否".equals(str)){ System.out.println("不行了,不跑了"); break; }else if("是".equals(str)){ System.out.println("接着跑"); i++; } } } }
原文链接:https://blog.csdn.net/single_panda29/article/details/135780318?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522171910766916800215073550%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=171910766916800215073550&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~times_rank-15-135780318-null-null.nonecase&utm_term=2024%E9%AB%98%E8%80%83%E6%88%90%E7%BB%A9