大数据day2 - Wayne53777/Java- GitHub Wiki

一、根据用户输入的年份,月份,判断该年该月有的多少天。

`package cn.zwz.day01; import java.util.Scanner; public class NianFen { @SuppressWarnings("resource") public static void main(String[] args) { int year,month; Scanner scan = new Scanner(System.in); System.out.println("请输入一个年份"); year = scan.nextInt(); System.out.println("请输入月份(1~12)"); month = scan.nextInt(); if(year%100 == 0 && year%400 == 0 && month == 2) System.out.println(29); else{ switch (month) { case 2:System.out.println(28);break; case 1: case 3: case 5: case 7: case 8: case 10: case 12: System.out.println(31);break; case 4: case 6: case 9: case 11: System.out.println(30);break; } } }

} > **二、条件结构判断** package cn.zwz.day01; import java.util.Scanner; public class TiaoJian { public static void main(String[] args) { @SuppressWarnings("resource") Scanner sc =new Scanner(System.in); System.out.println("请输入年份: ");//3.接收数据 int a = sc.nextInt(); System.out.println("请输入b: ");//3.接收数据 int b = sc.nextInt(); if (a==b) { System.out.println("两个数字相等"); } else { System.out.println("两个数字不相等"); } if(a%2 != 0) { System.out.println("a是奇数"); } else { System.out.println("a是偶数"); }

			if((a>=90) &&(a<=100) ) {System.out.println("最强王者");}
			else if((a>=80) &&(a<90)){System.out.println("星耀");}
			else if((a>=70) &&(a<80)){System.out.println("钻石");}
			else if((a>=60) &&(a<70)){System.out.println("黄金");}
			else if((a<60) &&(a>0)){System.out.println("黑铁");}
	 if(a%4==0 && a%100!=0){
	       System.out.print("是");
	    }else 
	    if(a%400==0){
	        System.out.print("是");
	    }   
	    else
	    {
	        System.out.print("不是");
	    }   

}

} **三、逻辑运算符**:package cn.zwz.day01; /**

  • 逻辑运算符与或非
  • */ public class LuoJi { public static void main(String[] args) { int x=10; int y=20; int z=30; System.out.println((x>y)&&(y>z));//False System.out.println((x>y)||(y<z));//true System.out.println((x>y) & (y>z)); System.out.println((x>y) | (y<z)); System.out.println((x++ >10)&&(++y <20)); System.out.println("x:" + x); System.out.println("y:" + y); System.out.println((++x >20)&&(y++ <20)&&(z-- <30)); System.out.println(x); System.out.println(y); System.out.println(z); System.out.println((x-- <10) & (y++ <20)); System.out.println(x); System.out.println(y); System.out.println(z); int u = (x>y)? x : y; System.out.println(u); }

} ` 四、循环结构

`package cn.zwz.day01;

public class Xunhuan { public static void main(String[] args) { int sum = 0; for(int i=1;i<=100;i++){ if(i%2==0){ sum=sum+i; } } System.out.println(sum);

}

} `>

⚠️ **GitHub.com Fallback** ⚠️