欢迎光临散文网 会员登陆 & 注册

作业代码(非最优

2019-11-04 04:03 作者:kands-code  | 我要投稿

import java.util.*;


public class njava06{

  public static void main(String[]args){

    //get imformation;

    System.out.println("Please enter your id :");

    Scanner in = new Scanner(System.in);

    String id = in.nextLine();

    int[] arr = new int[18];

    for (int i = 0;i < id.length();i++){

      String cup = String.valueOf(id.charAt(i));

      int num = Integer.parseInt(cup);

      arr[i] = num;

    }

    //computer the imformation;

    int year = 1000*arr[6]+100*arr[7]+10*arr[8]+arr[9];

    int month = 10*arr[10]+arr[11];

    int day = 10*arr[12]+arr[13];

    System.out.println("Please enter the year :");

    int nowYear = in.nextInt();

    System.out.println("Please enter the month :");

    int nowMonth = in.nextInt();

    System.out.println("Please enter the day :");

    int nowDay = in.nextInt();

    System.out.println("You born on "+year+"/"+month+"/"+day);

    //make a choice and print out;

    if(nowMonth == month){

      if(nowDay >= day){

        int age = nowYear - year;

        System.out.println("You are "+age+"years old.");

      }

      else{

        int age = nowYear - year -1;

        System.out.println("You are "+age+"years old.");

      }

    }

    else if(nowMonth > month){

      int age = nowYear - year;

      System.out.println("You are "+age+"years old.");

    }

    else{

      int age = nowYear - year -1;

      System.out.println("You are "+age+"years old.");

    }

    if(arr[16]%2 == 0){

      System.out.println("You are female");

    }

    else{

      System.out.println("You are male");

    }

    //get the code of imformation;

    int point = 0;

    for(int i = 0;i < id.length();i++){

      int b = arr[i]*((int)(java.lang.Math.pow(2,i))%11);

      point += b;

    }

    int codeInf = point%11;

    System.out.print("The code imformation is ");

    if(codeInf == 0){

      System.out.print(1);

    }

    else if(codeInf == 1){

      System.out.print(0); 

    }

    else if(codeInf == 2){

      System.out.print('X');

    }

    else{

      System.out.print(12-codeInf); 

    }

  }

}


作业代码(非最优的评论 (共 条)

分享到微博请遵守国家法律