在这里插入代码片
```//冒泡排序
public static void sort(int scores[]) {
for (int i = 0; i < scores.length; i++) {
for (int j = 0; j < scores.length-1-i; j++) {
if (scores[j]>scores[j+1]) {
int num = scores[j];
scores[j]=scores[j+1];
scores[j+1]=num;
}
}
}
}
```java
在这里插入代码片
```//选择排序
public static void sort2(int scores[]) {
int temp;
int minIndex;
for (int i = 0; i < scores.length-1; i++) {
minIndex=i;
for (int j = i+1; j < scores.length; j++) {
if (scores[minIndex]>scores[j]) {
minIndex=j;
}
}
if (i!=minIndex) {
temp= scores[i];
scores[i]=scores[minIndex];
scores[minIndex]=temp;
}
}
}
```java
在这里插入代码片
``` //求数组最大值
public static void maxNum(int scores[]) {
int max =0;
for (int i = 0; i < scores.length; i++) {
if (scores[i]>scores[max]) {
max=i;
}
}
System.out.println(scores[max]);
}
```java
在这里插入代码片
```//编写一个电脑类
public class Test2 {
String displayCard;
String brand;
int money;
String intemal;
int size;
int displaySize;
public static void main(String[] args) {
// TODO Auto-generated method stub
Test2 computer = new Test2();
computer.displayCard="1050Ti";
computer.brand="联想拯救者";
computer.money=6000;
computer.intemal="金士顿";
computer.size=8;
computer.displaySize=15;
computer.detail();
computer.look();
computer.playGame();
computer.study();
}
public void look() {
System.out.println("哈哈哈");
}
public void playGame() {
System.out.println("断剑重铸之日");
}
public void study() {
System.out.println("学个吊");
}
public void detail() {
System.out.println("显卡型号:"+displayCard);
System.out.println("品牌:"+brand);
System.out.println("价格:"+money);
System.out.println("内存品牌:"+intemal);
System.out.println("内存大小:"+size);
System.out.println("显示器尺寸:"+displaySize);
}
}
3.2Java作业
最新推荐文章于 2024-08-11 20:00:32 发布