Java大数据day3 - Wayne53777/Java- GitHub Wiki

一、身份证

package cn.zwz.day01;

import java.util.Scanner;

public class CardDemo { @SuppressWarnings("resource") public static void main(String[] args) { int card[] = new int[17]; int data[]= {7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2}; char[] code= {'1','0','X','9','8','7','6','5','4','3','2'}; Scanner sc = new Scanner (System.in); int sum = 0; for(int i= 0 ; i <card.length;i++ ){ System.out.println("请输入ID卡前17位:"); card[i]= sc.nextInt(); } for(int i= 0 ; i <card.length;i++ ) { sum += card[i]*data[i]; } System.out.println("最后一位:" + code[sum % 11]); } }

二、冒泡排序

package cn.zwz.day01; /*** * * * * * * * *

  • **/ public class MaoPao {

    public static void main(String[] args) { // TODO Auto-generated method stub int[] arr= {15,3,4,6,2,90,123,1}; for(int i=0;i<arr.length;i++){ for(int j=0;j<arr.length - 1 - i ;j++){ if(arr[j] > arr[ j + 1 ]) { int temp = arr[j]; arr[j]=arr[j+1]; arr[j+1]=temp;

     		}
     	}
     }
    

System.out.println("排序后数组:"); for(int i=0;i<arr.length;i++) { System.out.println(arr[i]); } }

} 三、循环

package cn.zwz.day01;

public class XxunHuan { public static void main(String[] args) { for(int x=100; x<1000; x++) { int a = x%10; int b = x/10%10; int c = x/100%10; if((aaa+bbb+ccc) == x) { System.out.println(x); } } } } 四、while

package cn.zwz.day01;

import java.util.Scanner;

/**

  • while循环

  • 猜的数字:int num = 456

  • 条件int guess;

  • while(guess != num){

  • 猜数字:

  • guess < num;

  • guess > num;

  • guess == num;break;

  • }

  • 猜对了!

  • */ public class WhXunhuan { @SuppressWarnings("resource") public static void main(String[] args) { int num = (int)((Math.random()*1000) + 1); Scanner sc = new Scanner(System.in); System.out.println("请输入一个数字"); int guess = sc.nextInt(); do { if(guess < num) { System.out.println("小了"); } else { System.out.println("大了");} System.out.println("继续"); guess = sc.nextInt(); if(guess == num) { System.out.println("猜对了"); } }while(guess != num); }

    }