藍橋杯_基礎_閏年判斷+01字串+字母圖形

閏年判斷

import java.util.Scanner;
public class Main {
// 先判斷400的情況,在判斷4和100的情況
    public static void main(String[] args) {
        int year = new Scanner(System.in).nextInt();
	    if(year % 400 == 0){
		System.out.println("yes");
			        }
	    else if((year % 4) == 0 && (year % 100) != 0){
		System.out.println("yes");
			        }

	    else{
		System.out.printf("no");
		                }

    }
}

01字串

import java.util.*;
// 2進制 利用嵌套for循環
public class Main{
    public static void main(String args[]){
        for(int a = 0;a < 2;a++)
	    for(int b = 0;b < 2;b++)
		for(int c = 0;c < 2;c++)
			for(int d = 0;d < 2;d++)
				for(int e = 0;e < 2;e++)
System.out.println(a+""+b+""+c+""+d+""+e);
								       
    }
}

字母圖形

import java.util.Scanner;
// 先預設一個字符串 按照規律從字符串相應的位置開始截取一定長度
public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		in.close();
		String str = "ZYXWVUTSRQPONMLKJIHGFEDCBABCDEFGHIJKLMNOPQRSTUVWXYZ";
		for(int i=0;i<n;i++) {
				System.out.println(str.substring((25-i),(25-i+m)));
		}
		
	}
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章