1、
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);
}
}
2、
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);
}
}
3、
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);
}
}
4、
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("你输入的是一个非负数");
}
}
}
5、
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("就这吧");
}
}
}
6、
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); } }
7、
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); } }
8、
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); } }
9、
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++; } } } }