1.定义长度位5的整型数组,输入他们的值,用冒泡排序后输出.
package day01;
import java.util.*;
public class test3 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input=new
Scanner (System.in);
int [] arr=new int [5];
System.out.println("input");
for (int i = 0; i < arr.length; i++) {
arr[i]=input.nextInt();
}
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr.length-i-1; j++) {
if(arr[j]>arr[j+1]){
int h=arr[j];
arr[j]=arr[j+1];
arr[j+1]=h;
}
}
}
for (int i = 0; i < arr.length; i++) {
System.out.println(arr[i]);
}
}
}
2.定义数组{34,22,35,67,45,66,12,33},输入一个数a,查找在数组中是否存在,如果存在,输出下标,不存在输出"not found"
import
java.util.*;
public
class
test3 {
public
static
void
main(String[] args) {
// TODO Auto-generated method stub
Scanner input=
new
Scanner (System.in);
int
[] arr={
34
,
22
,
35
,
67
,
45
,
66
,
12
,
33
};
int
x=
0
;
System.out.print(
"input a="
);
int
a=input.nextInt();
for
(
int
i =
0
; i < arr.length; i++) {
if
(a==arr[i]){
System.out.println(
"下标为"
+i);
x=
1
;
}
}
if
(x==
0
){
System.out.println(
"no found"
);
}
}
}
package day01;
public class yeah {
public static void main(String[] args) {
// TODO Auto-generated method stub
double [][] f={{1,2,3,4,5},{6,7,8,9,10},{11,12,13,14,15},{16,17,18,19,20}};
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 5; j++) {
System.out.print(f[i][j]);
}System.out.println();
}
}
}
4.定义一个二维数组(长度分别为3,4,值自己设定),求该二维数组的最大值.
package day01;
public class yeah {
public static void main(String[] args) {
// TODO Auto-generated method stub
int [][] ccc={{1,2,3,4},{6,7,8,9},{11,12,13,14}};
int max=0;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 4; j++) {
if(ccc[i][j]>max)
max=ccc[i][j];
}
}
System.out.println("max="+max);
}
}