选择题
接口中的方法是为了让重写
编程题
题目
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a_b = sc.nextInt();
int b_c = sc.nextInt();
int ab = sc.nextInt();
int bc = sc.nextInt();
for(int i = -100;i<=100;i++) {
for(int j = -100;j<=100;j++) {
for(int k = -100;k<=100;k++) {
if((i-j) == a_b) {
if((j-k) == b_c) {
if((i+j) == ab) {
if((j+k) == bc) {
System.out.print(i+" "+j+" "+k);
return ;
}
}
}
}
}
}
}
System.out.println("No");
sc.close();
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();//A-B
int b = sc.nextInt();//B-C
int c = sc.nextInt();//A+B
int d = sc.nextInt();//B+C
int A = (a+c)/2;
int B = (b+d)/2;
int C = B-b;
if((A-B)!=a || (B-C)!=b || (A+B)!=c || (B+C)!=d)
System.out.println("No");
else
System.out.println(A+" "+B+" "+C);
sc.close();
}
}
题目2
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int m = sc.nextInt();
int n = sc.nextInt();
StringBuffer s = new StringBuffer();
String res = "0123456789ABCDEF";
boolean f = false;
if(m == 0){
System.out.println(0);
return ;
}
if(m<0) {
m = -m;
f = true;
}
while(m!=0) {
s.append(res.charAt(m%n));
m/=n;
}
if(f) {
s.append('-');
}
System.out.println(s.reverse());
sc.close();
}
}