2024 蓝桥打卡Day34-代码练习

字符串排序

package THL_0406;

import java.util.Arrays;

public class ArrangeLetters {
	public static void main(String[] args) {
		String string = "WHERETHEREISAWILLTHEREISAWAY";
		char[] ch = string.toCharArray();
		Arrays.sort(ch);
		System.out.println(ch);
		
		
	}
}

大小写转换 (ccfcsp之前要是学了我就能上200了 啊啊啊啊 错过啊)

package THL_0406;

import java.util.Scanner;

public class CaseConversion {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		String string = sc.next();
				
		// 异或
		char[] ch = string.toCharArray();
		for(int i=0;i<ch.length;i++) {
			ch[i] = (char) (ch[i] ^ 32); // 将大写字母转成小写字母,将小写字母转成大写字母
		}
		System.out.print("大小写互换为:"+" ");
		System.out.println(ch);

		
		System.out.println("全部转换成小写字母:"+string.toLowerCase()+"全部转换成大写字母:"+string.toUpperCase());

	}
}

斐波那契数列 递归解法

package THL_0406;

import java.util.Scanner;

public class Fibonacci {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		System.out.println(Fibonacci(num));

	}
	
	public static int Fibonacci(int n) {
		if(n==1||n==2) {
			return 1;
		}else {
			return Fibonacci(n-1) + Fibonacci(n-2);
		}
	}
}

纸张尺寸问题

package THL_0406;

import java.util.Scanner;

public class Fibonacci {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		System.out.println(Fibonacci(num));

	}
	
	public static int Fibonacci(int n) {
		if(n==1||n==2) {
			return 1;
		}else {
			return Fibonacci(n-1) + Fibonacci(n-2);
		}
	}
}
上一篇:redis安装建立连接


下一篇:Django如何定义视图函数?FBV-CBV的使用场景