选择题
public class Test01 {
public static void main(String[] args){
System.out.println(new B().getValue());
//1\new B()
//2\.getValue()
//16然后去getValue()
//结果为:22、34、17
}
static class A{
protected int value;
public A(int v) {//5
setValue(v);//调用的是子类重写的
}
public void setValue(int value){
this.value = value;//10//22//16
}
public int getValue(){
try{
value++;//11//17
return value;//11//17
} catch(Exception e){
System.out.println(e.toString());
} finally {
this.setValue(value);//调用的是子类重写的 11//调用的是子类重写的 17
System.out.println(value);//22//34
}
return value;
}
}
static class B extends A{
public B() {
super (5);
setValue(getValue() - 3);//11-3 = 8//
}
public void setValue(int value){
super.setValue(2 * value);//10//22//16//34
}
}
}
编程题
题目1
import java.util.Scanner;
public class Main {
public static int gcd(int a,int b) {
return a%b==0?b:gcd(b,a%b);
}
public static int lcm(int a,int b) {
return (a*b)/gcd(a,b);
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
//先求最大公约数
//int s1 = gcd(a,b);
//再求最小公倍数
int s2 = lcm(a,b);
System.out.println(s2);
sc.close();
}
}
题目2
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
String[] sum = new String[n];
boolean f1 = false;
boolean f2 = false;
sc.nextLine();
for(int i=0;i<n;i++) {
String s = sc.next();
sum[i] = s;
//c
//bb
//aaa
if(i>=1) {
if(sum[i].length()>=sum[i-1].length()) {
f1 = true;
}else {
f1 = false;
}
if(sum[i].compareTo(sum[i-1])>=0) {
f2 = true;
}else {
f2 = false;
}
}
}
if(f1 && !f2) {
System.out.println("lengths");
return ;
}
if(!f1 && f2) {
System.out.println("lexicographically");
return ;
}
if(f1 && f2) {
System.out.println("both");
}else {
System.out.println("none");
}
sc.close();
}
}