小游戏_猜数_JAVA
生活随笔
收集整理的這篇文章主要介紹了
小游戏_猜数_JAVA
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
import javax.swing.JOptionPane;public class Main {public static void main(String[] args) {System.out.println("給你一個1至100之間的整數,試著猜一猜這個數");int realNumber = (int)(Math.random() * 100) + 1;int yourGuess = 0;String str = JOptionPane.showInputDialog("請輸入你的猜測:");yourGuess = Integer.parseInt(str);while(yourGuess != realNumber) {if(yourGuess > realNumber) {str = JOptionPane.showInputDialog("猜大了,在輸入你的猜測:");yourGuess = Integer.parseInt(str);}else if(yourGuess < realNumber) {str = JOptionPane.showInputDialog("猜小了,在輸入你的猜測:");yourGuess = Integer.parseInt(str);}}System.out.println("猜對了!恭喜您");}}
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀
總結
以上是生活随笔為你收集整理的小游戏_猜数_JAVA的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 数据结构实验之图论七:驴友计划(最短路F
- 下一篇: 实验五 输入输出练习_JAVA