1 Packageday04;2 3 ImportJava.util.Scanner;4 5 Public classFundamental {6 7 8 9 Ten Public Static voidMain (string[] args) { One ASystem.out.println ("Welcome to try to guess the alphabet game"); - -Scanner scan =NewScanner (system.in); the //String arr = Scan.next (); - Char[] input =NULL; - //input = Arr.tochararray (); - Char[] str=Guess (); + for(intk=0;k<5;k++) - System.out.print (Str[k]); + intCount=0; ASystem.out.println ("Start the game, please enter the five-letter sequence you guessed: (exit! Exit) "); at while(true){ -String arr =scan.next (). Trim (). toUpperCase (); - if(Arr.equals ("exit!")){ -System.out.println ("Game Over! "); - Break; - } ininput =Arr.tochararray (); - int[] sum=check (str,input); to intscore=500-10*count; + if(sum[0]==5){ -System.out.println ("Congratulations you guessed right, your score is:" +score); the * } $ Else{Panax NotoginsengSystem.out.println ("You guessed the" +sum[1]+ "character" + ", where there are" +sum[0]+ "characters in the correct position"); - the } +count++; A //check (); the //Guess (); + } - $ } $ - - Public Static Char[] Guess () { the - Char[] str =New Char[5];Wuyi Char[] zmb={' A ', ' B ', ' C ', ' D ', ' E ', ' F ', ' G ', ' H ', ' I ', ' J ', ' K ', ' L ', ' M ', ' N ', ' O ', ' P ', the' Q ', ' R ', ' S ', ' T ', ' U ', ' V ', ' W ', ' X ', ' Y ', ' Z '}; - Boolean[] flag =New Boolean[zmb.length]; Wu - for(inti=0;i<str.length;i++){ About intnum; $ Do{ -num = (int) (Math.random () *zmb.length); - - A} while(Flag[num]); +str[i]=Zmb[num]; theflag[num]=true; - } $ returnstr; the } the the Public Static int[] Check (Char[] str,Char[] input) { the int[] sum =New int[2]; - for(inti=0;i<5;i++){ in for(intj=0;j<5;j++){ the if(str[i]==Input[j]) { theSum[1]+=1; About if(i==j) { theSum[0]+=1; the the } + Break; - } the Bayi the } the - } - returnsum; the } the the the}
JAVA fundamental--20150804