字符串排序
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);
}
}
}