单分支练习

import java.util.Scanner;

public class IfExercise01 {
	//main
	public static void main(String[] args){
		double dn1 = 11.0;
		double dn2 = 10.0;
		if (dn1>10.0 && dn2<20.0){
			System.out.println(dn1+dn2); //输出21
		}


		int in1= 10;
		int in2= 5;
		if ((in1+in2)%3 == 0 && (in1+in2)%5==0){
			System.out.println("这两个数之和可用整除3和5"); //输出
		}

		//判断是否是闰年
		Scanner yearScaner = new Scanner(System.in);
		int year = yearScaner.nextInt();
		if (year%4==0 && year%100!=0 || year%400==0 ){
			System.out.println(year+"是闰年");
		}
		else{
			System.out.println(year+"不是闰年");
		}
	}
}

多分支练习

import java.util.Scanner;

public class If03 {
	//main
	public static void main(String[] args){
		Scanner creditScanner = new Scanner(System.in);
		System.out.println("请输入保国同志的信用分:");
		int creidt = creditScanner.nextInt();
		if(creidt >= 0 && creidt <= 100){
			if (creidt  == 100){
				System.out.println("信用极好");
			}
			else if (creidt >= 80 && creidt <= 99){
				System.out.println("信用优秀");
			}
			else if (creidt < 80 && creidt >= 60){
				System.out.println("信用一般");
			}
			else{
				System.out.println("信用不及格");
			}
		}else {
			System.out.println("输入的信用分超出范围");
		}
	}
}