第七次作业

发布时间 2023-06-06 01:39:31作者: 小楠参
一。

 

 

package com.sykjxy.jsj;

public class hello {
public static void main(String[] args) {
System.out.println();
int x[]= {1,5,7,3,2,9,4};

paixu(x);

for(int i=0;i<x.length;i++) {

System.out.println(x[i]);

}

}



public static void paixu(int a[]) {

for(int i=0;i<a.length-1;i++) {

for (int j=0;j<a.length-1-i;j++) {

if(a[j]>a[j+1]) {

int temp=a[j];

a[j]=a[j+1];

a[j+1]=temp;

}

}

}

}

}
二。
package com.sykjxy.jsj;

public class hello {
public static void main(String[] args) {
int sum1=jc(5);

System.out.println(sum1);

}

public static int jc(int n) {

int sum=1;

for(int i=1;i<=n;i++) {

sum*=i;

}

return sum;

}
}

 三。

package com.sykjxy.jsj;
import java.util.Scanner;
public class hello {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);

System.out.println("输入年份:");

int year = input.nextInt();

if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {

System.out.println(year + "是闰年");

} else {

System.out.println(year + "是平年");

}
}
}

 四。

package com.sykjxy.jsj;
import java.util.Scanner;
public class hello {
public double getArea(double r) {

double mj=0;

mj=3.14*r*r;

return mj;

}

// 求矩形面积的方法

public double getArea(double a,double b) {

return a*b;

}
}



package com.sykjxy.jsj;

public class hi {
public static void main(String[] args) {

// TODO Auto-generated method stub

hello m=new hello();

System.out.println("圆的面积为:"+m.getArea(10));

System.out.println("矩形的面积为:"+m.getArea(5.5, 10));

}

}

 五。

package com.sykjxy.jsj;
public class hello {
public static void main(String[] ards) {

hi b1 = new hi('黑', 2000);

hi b2 = new hi('白', 2500);

System.out.println(b1.toString());

System.out.println(b2.toString());

hi b3 = new hi();

b3.setColor('红');

b3.setCpu(3000);

System.out.println(b3.toString());

}
}
package com.sykjxy.jsj;

public class hi {

private char color;
private int cpu;

public hi(char color, int cpu) {
super();
this.color = color;
this.cpu = cpu;
}
public hi() {
}

public char getColor() {

return color;

}

public void setColor(char color) {

this.color = color;

}

public int getCpu() {

return cpu;

}

public void setCpu(int cpu) {

this.cpu = cpu;

}

@Override

public String toString() {

return "笔记本的信息 [颜色为" + color + ", cpu为" + cpu + "]";

}

}