JAVA试卷求解~

2024-11-27 03:43:48
推荐回答(5个)
回答1:

1.
float min;
float max;
min = Math.min(f1, f2);
min = Math.min(min, f3);
max = Math.max(f1, f2);
max = Math.max(max, f3);

2.
一共4个: 153, 370, 371, 407
int count=0;
for(int i=100;i<1000;i++) {
int a = i/100;
int b = (i%100)/10;
int c = i%10;
if(a*a*a+b*b*b+c*c*c == i) count++;
}
System.out.print(count);

3.
int v = (I+1)*I/2;

4.
for(int n=101;n<999;n+=2) {
boolean prime = true;
for (long i = 3; i <= Math.sqrt(n); i += 2)
if (n % i == 0) {
prime = false;
break;
}
if(prime) System.out.print(n+" ");

}

5.
int r = 1;
for(int i=2;i<=120;i++) {
r*=i;
if(i==5 || i==6 || i==20 || i==120) System.out.print(r+" ");
}

6.
for(int i=100;i<=500;i++)
if(i%3!=0 && i%7!=0)
System.out.println(i);

7.
int[] a = {56,132,567,980.89,212.098,-78};
Arrays.sort(a);
for(int i:a) System.out.print(i+" ");

8.
int[] fib = new int[300];
fib[0] = fib[1] = 1;
for(int i=2;i<300;i++)
fib[i] = fib[i-1] + fib[i-2];
for(int i:fib) System.out.print(i+" ");

9.
class SimpleRect {
//无图
}

10.
class mySimpleRect extends SimpleRect {
int circumference, area;
Color fill, border;
Point location, size;
int calculateCircumference() {
return circumference = (size.x+size.y)*2;
}
int calculateArea() {
return area = size.x*size.y;
}
void setFillColor(Color c) {
fill=c;
}
void setBorderColor(Color c) {
border=c;
}
Color getFillColor() {
return fill;
}
Color getBorderColor() {
return border;
}
void setLocation(Point p) {
location=p;
}
void setSize(Point p) {
size=p;
}
void paint(Graphics g) {
g.setColor(fill);
g.fillRect(location.x, location.y, size.x, size.y);
g.setColor(border);
g.drawRect(location.x, location.y, size.x, size.y);
}
}

11.
class GetString {
String getString() {
Scanner scan = new Scanner(System.in);
return scan.nextLine();
}
}

12.
class GetDouble extends GetString {
double getDouble() {
return Double.parseDouble(getString());
}
}

class GetInteger extends GetString {
double getInteger() {
return Integer.parseInteger(getString());
}
}

回答2:

不算难,就是太多了,没时间帮你写了

回答3:

太基础
懒得写了

回答4:

有的简单,有的就难了,你的20分太少了,不值的去做,一题20还差不多

回答5:

都是 基础啊

这种问题 CSDN 上 一堆一堆的 LZ 去那看看