In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces Java how to achieve word-guessing Mini Game, the article is very detailed, has a certain reference value, interested friends must read it!
The specific code is as follows:
Package test07;import java.util.Scanner;// guessing character game public class Guessing {/ / main method public static void main (String [] args) {Scanner scan = new Scanner (System.in); char [] chs = generate (); / / get random character array System.out.println (chs); / / cheat int count = 0; / / number of guesses while (true) {/ / self-made loop System.out.println ("guess!") String str = scan.nextLine (). ToUpperCase (); / / receive the string entered by the user and convert it to uppercase if (str.equals ("EXIT")) {/ / determine whether the string content is EXITSystem.out.println ("come again!"); break;} char [] input = str.toCharArray (); / / convert the string to a character array int [] result = check (chs,input) / / comparison: the random character array and the character array entered by the user if (result [0] = = chs.length) {/ / a pair of int score = 100 characters, deducting 10 points for each wrong guess ("Congratulations on your guess right, score:" + score); break;} else {/ / wrong count++ / / increase the number of error guesses by 1System.out.println ("the number of character pairs is" + result [1] + ", the number of position pairs is" + result [0]);} / / generate a random character array chspublic static char [] generate () {char [] chs = new char [5] / / Random character array char [] letters = {'A','B','C','D','E','F','G','Ha','I','J'C','L','M','N','O','P','Q','R','S','T','U','V' 'Xray, 'Yee,' Z'} / / Random character range array boolean [] flags = new boolean [letters.length]; / / tagged array for (int iCharacter I
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.