package text1;
public class Dome1 {
public static void main(String[] args) {
int a[] = {16,25,9,90,23};
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;
}
}
}
for (int i=0;i< a.length;i++) {
System.out.print(a[i]+"\t");
}
}
}
```java
9 16 23 25 90
进程已结束,退出代码为 0
package text1;
public class Dome2 {
public static void main(String[] args) {
int[] a = {16, 25, 9, 90, 23};
boolean flag = false;
for (int i = 0; i < a.length - 1; i++) {
flag = false;
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;
flag = true;
}
}
if (flag = false) {
break;
}
}
for (int i = 0; i < a.length; i++) {
System.out.print(a[i] + "\t");
}
}
}
9 16 23 25 90
进程已结束,退出代码为 0
```java
在这里插入代码片
package text1;
import java.util.Scanner;
public class Three {
public static void main(String[] args) {
Scanner input = new Scanner (System.in);
System.out.println("请输入5句话:");
String[] names = new String [5];
for (int i = 0; i < names.length; i++) {
System.out.print("第"+(i+1)+"句话:");
names[i]=input.next();
}
System.out.println("逆序输出的5句话为:");
for (int i = names.length-1; i >=0; i--) {
System.out.println(names[i]);
}
}
}
请输入5句话:
第1句话:晴
第2句话:画
第3句话:天
第4句话:明
第5句话:诗
逆序输出的5句话为:
诗
明
天
画
晴
进程已结束,退出代码为 0
package text1;
public class Four {
public static void main(String[] args) {
System.out.println("原数组:");
int [] array = new int[]{1,3,-1,5,-2};
for (int i = 0; i < array.length; i++) {
System.out.print(array[i]+"\t");
}
System.out.println("\n");
System.out.println("排序后数组为:"+"\t");
int Array[] = new int[5];
int top=0;
for (int i = 0; i < array.length-1; i++) {
for (int j = 0; j < array.length-1-i; j++) {
if(array[j]>array[j+1]){
top = array[j];
array[j] = array[j+1];
array[j+1] = top;
}
}
}
for (int i = 0; i < array.length; i++) {
System.out.print(array[i]+"\t");
}
}
}
原数组:
1 3 -1 5 -2
排序后数组为:
-2 -1 1 3 5
进程已结束,退出代码为 0
package text1;
import java.util.Scanner;
public class Five {
public static void main(String[] args) {
int a=10;
int[]num = new int[a];
int[] b = new int[4];
System.out.println("请输入10个数:");
for (int i = 0; i < num.length; i++) {
Scanner input=new Scanner(System.in);
num[i]= input.nextInt();
if (num[i]==1){
b[1]++;
}
else if (num[i]==2){
b[2]++;
}
else if (num[i]==3){
b[3]++;
}
else{
b[0]++;
}
}
System.out.print("输入的10个数为:" );
for(a=0;a<10;a++) {
System.out.print( num[a]+" ");
}
System.out.println("\n数字1的个数:" + b[1]);
System.out.println("数字2的个数:" + b[2]);
System.out.println("数字3的个数:" + b[3]);
System.out.println("非法数字的个数:" + b[0]);
}
}
请输入10个数:
2
3
5
8
2
9
3
4
6
7
输入的10个数为:2 3 5 8 2 9 3 4 6 7
数字1的个数:0
数字2的个数:2
数字3的个数:2
非法数字的个数:6
进程已结束,退出代码为 0
package text1;
public class Six {
public static void main(String[] args) {
int[][]array=new int[][]{{80,66},{70,54,98},{77,59}};
int total;
for (int i = 0;i< array.length;i++ ){
String str=(i+1)+"班";
total=0;
for (int j = 0;j<array[i].length;j++) {
total += array[i][j];
}
System.out.println(str+"总成绩"+total);
}
}
}
1班总成绩146
2班总成绩222
3班总成绩136
进程已结束,退出代码为 0