In: Computer Science
Write a Java program called Decision that includes a while loop to prompt the user to enter 5 marks using the JOptionPane statement and a System. Out statement to output a message inside the loop highlighting a pass mark >= 50 and <= 100. Any other mark will output a messaging stating it’s a fail.
Code:
import javax.swing.*; // import swing library
// declare a class
public class Main {
JFrame f;
Main(){
int count=5;
f=new JFrame(); // create an object
// display dialogue box
JOptionPane.showMessageDialog(f,"Enter 5 marks.");
while(count-- > 0){
String mark =JOptionPane.showInputDialog(f,"Enter mark: ");
int a = Integer.parseInt(mark);
if(a>=50 && a<=100){
System.out.print("\nPass!");
}else{
System.out.println("\nFail!");
}
}
}
public static void main(String[] args) {
new Main();
}
}
(Throw an upvote or comment if you have any doubts.)