1.
package
week;
import
java.util.Scanner;
public
class
zy {
public
static
void
main(String[] args) {
// TODO Auto-generated method stub
int
[] num =
new
int
[
5
];
Scanner input =
new
Scanner(System.in);
for
(
int
i =
0
; i < num.length; i++) {
System.out.print(
"请输入第"
+ (i +
1
) +
"个数:"
);
num[i] = input.nextInt();
}
for
(
int
i =
0
; i < num.length -
1
; i++) {
for
(
int
j =
0
; j < num.length -
1
- i; j++) {
if
(num[j] > num[j +
1
]) {
int
temp = num[j];
num[j] = num[j +
1
];
num[j +
1
] = temp;
}
}
}
for
(
int
i =
0
; i < num.length; i++) {
System.out.print(num[i] +
" "
);
}
}
}
2.
package week;
import java.util.Scanner;
public class zy {
public static void main(String[] args) {
//2.定义数组{34,22,35,67,45,66,12,33},输入一个数a,查找在数组中是否存在,如果存在,输出下标,不存在输出"not found"
int[] arr = {34,22,35,67,45,66,12,33};
int j=0;
Scanner sc = new Scanner(System.in);
System.out.println("请输入一个数");
int a = sc.nextInt();
for(int i = 0;i<arr.length;i++) {
if(a==arr[i]) {
j=1;
int xiabiao = i;
System.out.println("下标为:"+xiabiao);
break;
}
}if(j==0) {
System.out.println("no found");
}
}
}
import java.util.Scanner;
public class zy {
public static void main(String[] args) {
//2.定义数组{34,22,35,67,45,66,12,33},输入一个数a,查找在数组中是否存在,如果存在,输出下标,不存在输出"not found"
int[] arr = {34,22,35,67,45,66,12,33};
int j=0;
Scanner sc = new Scanner(System.in);
System.out.println("请输入一个数");
int a = sc.nextInt();
for(int i = 0;i<arr.length;i++) {
if(a==arr[i]) {
j=1;
int xiabiao = i;
System.out.println("下标为:"+xiabiao);
break;
}
}if(j==0) {
System.out.println("no found");
}
}
}
3.
package week;
public class zy {
public static void main(String[] args) {
// TODO Auto-generated method stub
double[][] a = { { 1.1, 3.2, 5.3, 7.4 }, { 9.1, 11,2, 13.3, 15.4 },
{ 17.1, 19.2, 21.3, 23.4 }, { 25.1, 27.2, 29.3, 31.4 },
{ 33, 35, 37, 39 } };
for (int i = 0; i < a.length; i++) {
for (int j = 0; j < a.length - 1; j++) {
System.out.print(arr[i][j] + " ");
}
System.out.println(" ");
}
}
}
public class zy {
public static void main(String[] args) {
// TODO Auto-generated method stub
double[][] a = { { 1.1, 3.2, 5.3, 7.4 }, { 9.1, 11,2, 13.3, 15.4 },
{ 17.1, 19.2, 21.3, 23.4 }, { 25.1, 27.2, 29.3, 31.4 },
{ 33, 35, 37, 39 } };
for (int i = 0; i < a.length; i++) {
for (int j = 0; j < a.length - 1; j++) {
System.out.print(arr[i][j] + " ");
}
System.out.println(" ");
}
}
}
4.
package week;
public class zy{
public static void main(String[] args) {
//4.定义一个二维数组(长度分别为3,4,值自己设定),求该二维数组的最大值.
int[][] arr = {{10,21,31,14},{15,26,38,47},{18,24,83,46}};
int max = arr[0][0];
for(int i = 0;i<arr.length;i++) {
for(int j = 0;j< arr[i].length;j++) {
if(arr[i][j]>max) {
max = arr[i][j];
}
}
}System.out.println(max);
}
}
public class zy{
public static void main(String[] args) {
//4.定义一个二维数组(长度分别为3,4,值自己设定),求该二维数组的最大值.
int[][] arr = {{10,21,31,14},{15,26,38,47},{18,24,83,46}};
int max = arr[0][0];
for(int i = 0;i<arr.length;i++) {
for(int j = 0;j< arr[i].length;j++) {
if(arr[i][j]>max) {
max = arr[i][j];
}
}
}System.out.println(max);
}
}