JAVA fundamental--20150804

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.