當前位置:編程學習大全網 - 編程軟體 - java編程:幸運52遊戲。要求用戶對物品的價格進行估測

java編程:幸運52遊戲。要求用戶對物品的價格進行估測

import javax.swing.JOptionPane;

public class Example{

static int right = (int)(Math.random()*100);

public static void main(String args[]){

in();

}

private static int in() {

int index = Integer.parseInt(JOptionPane.showInputDialog("請輸入:"));

for(;;){

if(index<right){

JOptionPane.showMessageDialog(null, "小了");

index = Integer.parseInt(JOptionPane.showInputDialog("請重新輸入:"));

}else{

if(index>right){

JOptionPane.showMessageDialog(null, "大了");

index = Integer.parseInt(JOptionPane.showInputDialog("請重新輸入:"));

}else{

JOptionPane.showMessageDialog(null, "恭喜妳答對了!!");

return 0;

}

}

}

}

}

這個只是簡單實現,這個程序只有在妳答對的情況下,才會退出,妳看看符合妳的要求不?

  • 上一篇:京瓷181復印機代碼
  • 下一篇:好聽的電競昵稱有哪些?
  • copyright 2024編程學習大全網