java - 调节字符串

标签 java conditional-statements poker

快速提问。我想知道如何才能做到这一点,以便它仅在用户输入 2-23 之间的数字时运行。

         BufferedReader in;
         int x;
         String playerx;

         //user input for number of players
         in = new BufferedReader(new InputStreamReader(System.in));
         System.out.println("\nWelcome to the Casino!");
         System.out.println("How many players are playing? (2-23)");
         //string for number of players
         playerx = in.readLine(); 
         //convert players to integer
         x = Integer.valueOf(playerx).intValue(); 

         //condition player x so that the number of players are between 2 and 23
         if(playerx.compareTo("1")==0 && playerx.compareTo("24")==0) {
            System.out.println("\nSorry, there are either not enough players or not enough cards for that option.");
        }else { 

最佳答案

由于您已经有了玩家数量的 int 值,即 x,因此最好进行比较以保持简单。

更改此:

     if(playerx.compareTo("1")==0 && playerx.compareTo("24")==0) {

     if(x > 1 && x > 24) {

关于java - 调节字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19216663/

相关文章:

java - 如何在java中仅将一个值分配给数组的第零个索引,并且所有值都在该数组中

java - Java中向子进程发送信号

java - IntelliJ - 当 i 已知时,不会出现条件 i >= 2 的警告消息

c# 直接检查扑克牌

Java PokerHand 方法

java - 音频:更改字节数组中样本的音量

java - 变量已定义但仍无法解析

Python:条形图 - 绘制所有年份中 a) 年和 b) 季度的值总和

python - 根据最大值和最小值填写缺失的日期 pandas