In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-12 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how to achieve JAVA guess number case, Xiaobian feel quite practical, so share to everyone as a reference, I hope you can gain something after reading this article.
This is an actual mixed use case for Scanner,Random, Loop, Conditional, Break.
/* Mini games for guessing numbers Random number a number, let the user guess Results Three conditions: Hit, big, small. Random Number: Random Keyboard input: Scanner Guess the number, compare it with a random number if judged while*/import java.util.Random;import java. util.Scanner;public class GuestNumber{ public static void main(String[] args){ System.out.println("Start guessing numbers"); System.out.println("Enter data between 1 and 100"); //Create Random class variable Random ran = new Random(); //Variable. Use the function nextInt() to get random numbers from 1 to 100 int ranNumber = ran.nextInt(100)+1; //System.out.println(ranNumber); //Create Scanner class variable Scanner sc = new Scanner(System.in); while(true){ //Get keyboard input int number = sc.nextInt(); //random numbers and, user-entered data, comparison if( number > ranNumber){ System.out.println(""); }else if (number < ranNumber){ System.out.println(""); }else{ System.out.println(""); break; } } }}
About "how to achieve JAVA guess number case" this article is shared here, I hope the above content can be of some help to everyone, so that you can learn more knowledge, if you think the article is good, please share it to let more people see.
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: 255
*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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.