选择题
public class Test01{private static int x = 100;public static void main(String[] args) {Test01 hs1 = new Test01();hs1.x++;Test01 hs2 = new Test01();hs2.x++;hs1=new Test01();hs1.x++;Test01.x--;System.out.println("x="+x);}
}
public class Test01{private static int x = 100;public static void main(String[] args) {Test01 hs1 = new Test01();hs1.x++;
// System.out.println("x="+x);101Test01 hs2 = new Test01();hs2.x++;
// System.out.println("x="+x);102hs1=new Test01();hs1.x++;
// System.out.println("x="+x);103Test01.x--;System.out.println("x="+x);//102}
}
public class Test01{public static void main(String[] args) {C c = new C();}
}
class A{A(){System.out.println("A");}
}class B extends A{B(){System.out.println("B");}
}class C extends B{C(){System.out.println("C");}
}
//A
//B
//C
编程题
题目1
import java.util.Scanner;public class Main{public static void main(String[] args) {Scanner sc = new Scanner(System.in);int n = sc.nextInt();long[] f = new long[32];f[0] = 0;f[1] = 1;for(int i=2;i<=31;i++)f[i] = f[i-1] + f[i-2]; long sum = 0 ;long min = 1000000 ;for(int i=0;i<=31;i++) {sum = Math.abs(f[i]-n);if(sum<min)min = sum;}System.out.println(min);sc.close();}
}
题目2
import java.util.*;public class Parenthesis {public boolean chkParenthesis(String A, int n) {Deque<Character> dq = new LinkedList<>();char[] c = A.toCharArray();for (int i = 0; i < c.length; i++) {// if(c[i]>='a' && c[i]<='z')// return false;if (c[i] == '(') {dq.addFirst(c[i]);// System.out.println("add" + dq);}if (c[i] == ')') {if (dq.isEmpty()) {// System.out.println("for false");return false;}dq.removeFirst();// System.out.println("remove" + dq);}}if (dq.isEmpty())return true;else {// System.out.println("return" + dq);return false;}}
}