JOptionPane 使用 if else 语句进行输入验证

问题描述 投票:0回答:1

我想当用户输入一个不超过 100 的正整数时,它会显示一条错误消息,如果输入正确,用户将再次输入,然后继续执行 if/else 语句。

import java.util.Scanner;
import javax.swing.JOptionPane;

public class Culminating {

    public static void main(String[] args) {
          Scanner  in = new Scanner (System.in);
       JOptionPane.showMessageDialog(null, "WELCOME");
        String userInput = JOptionPane.showInputDialog("KINDLY ENTER YOUR GRADES");
       int num = Integer.parseInt(userInput);
      
       
       if (num>100)
     {
    JOptionPane.showMessageDialog(null, "ERROR: PLEASE ENTER UP TO 100 ONLY" ); 
    
     }  
       
       else if (num>93)
     {
    JOptionPane.showMessageDialog(null, "Letter Grade: " + " A " + "\n\nPoints: " + 4.0 ); 
     }  
       
    else if (num > 90 )
    {
    JOptionPane.showMessageDialog(null, "Letter Grade: " +" A- " + "\n\nPoints: " + 3.7 ); 
    }
    
    else if (num> 87){
    JOptionPane.showMessageDialog(null, "Letter Grade: " + " B+ " + "\n\nPoints: " + 3.3 ); 
    }
       
    else if (num> 83){
    JOptionPane.showMessageDialog(null, "Letter Grade: " + " B " + "\n\nPoints: " + 3.0 ); 
    }
       
    else if (num>80){
    JOptionPane.showMessageDialog(null, "Letter Grade: " + " B- " + "\n\nPoints: " + 2.7 ); 
    }
       
    else if (num>77){
   JOptionPane.showMessageDialog(null, "Letter Grade: " + " C+ " + "\n\nPoints: " + 2.3 ); 
    }
    
    else if (num>73){
    JOptionPane.showMessageDialog(null, "Letter Grade: " + " C " + "\n\nPoints: " + 2.0 ); 
    }
       
    else if (num> 70){
    JOptionPane.showMessageDialog(null, "Letter Grade: " + " C- " + "\n\nPoints: " + 1.7 ); 
    }
    
    else if (num> 67){
    JOptionPane.showMessageDialog(null, "Letter Grade: " + " D+ " + "\n\nPoints: " + 1.3 ); 
    }
    
    else if (num>64){
    JOptionPane.showMessageDialog(null, "Letter Grade: " + " D " + "\n\nPoints: " + 1.0 ); 
    }
    
    else if (num<64){
    JOptionPane.showMessageDialog(null, "Letter Grade: " + " E " + "\n\nPoints: " + 0.0 ); 
    } 
       }
}
java swing validation input joptionpane
1个回答
0
投票

คะแนน)จงเขียนโปรแกรมรับค่าผ่านแป้นพิมพ์ในการค ำนวณภาษีโดยมีเงื่อนไขดังนี้ 1 รับค่าจำนวนเงิน • 费用 0-150,000 费用 • 费用 150,001-300,000 费用 5% • 费用 300,001-500,000 费用 10% • 费用 500,001-750,000 费用 15% • 费用 750,001-1,000,000 费用 20% • 1,000,001-2,000,000 欧元 25% • 费用 2,000,001-5,000,000 费用 30% • 5,000,000 บาทขึ้นไป อัตราภาษี 35%

© www.soinside.com 2019 - 2024. All rights reserved.