第六周作业

package set;

import java.util.Scanner;

public class SKSK {

	public static void main(String[] args) {
		 int[] num = new int[5];
	        Scanner input = new Scanner(System.in);
	        for (int a = 0; a < num.length; a++) {
	            System.out.print("请输入第" + (a + 1) + "个数:");
	            num[a] = input.nextInt();
	        }
	        for (int b = 0; b < num.length - 1; b++) {
	            for (int c = 0; c < num.length - 1 - b; c++) {
	                if (num[c] > num[c + 1]) {
	                    int temp = num[c];
	                    num[c] = num[c + 1];
	                    num[c + 1] = temp;
	                }
	            }
	        }
	        for (int i = 0; i < num.length; i++) {
	            System.out.print(num[i] + " ");
	     }
}
	}

  

 

 

package set;

import java.util.Scanner;

public class SKSK {

	public static void main(String[] args) {	
        Scanner input = new Scanner(System.in);
        int[] arr = {34,22,35,67,45,66,12,33};
        int a=-1;
        int b;
        System.out.println("输入一个数");
        int c=input.nextInt();
        for(int i =0;i<arr.length;i++) {
            if(arr[i] == c) {
                a = i;
                System.out.println("下标为"+i);
                break;
            }
        }if(a == -1) {
            System.out.println("not found");
        }
}

	}

  

 

 

 

 

package set;

public class SKSK {

	public static void main(String[] args) {	
	       double[][] a= {{3.8,7.7,2.0,3.3,15.0},{2.1,5.5,8.4,33.3,12.0},
	                {44.4,40.1,3.5,5.4,1.11},{2.2,8.8,9.99,9.98,5.57}};
	        for (int b = 0; b < a.length; b++) {
	            for (int j = 0; j < 5; j++) {
	                System.out.print(a[b][j]+"\t");
	            }
	            System.out.print("\n");
	        }
	    }
}

  

 

 

package set;

import java.util.Scanner;

public class SKSK {

	public static void main(String[] args) {
		 Scanner input=new Scanner(System.in);
         System.out.println("请输入数组的值:");
         int [][] a=new int[3][4];    
         for(int i=0;i<a.length;i++) {
              for(int j=0;j<a[i].length;j++) {
               a[i][j]=input.nextInt();
              }
             }
         int max=0;
         for(int i=0;i<a.length;i++) {
          for(int j=0;j<a[i].length;j++) {
           if(max<a[i][j]) {
            max=a[i][j];
           }}}
         System.out.println("最大值为"+max);
        }
}

  

 

posted @ 2020-04-12 14:02  Demens  阅读(121)  评论(0编辑  收藏  举报