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.
Example of the expected output is as follows:
import javax.swing.*;
public class InputDemo
{
public static void main(String args[])
{
int n = 0;
while(n<5){
String str1 = JOptionPane.showInputDialog("Enter Marks");
double marks = Double.parseDouble(str1);
if(marks>=50 && marks<=100){
System.out.println("Marks:"+marks+" Status:Pass");
}else{
System.out.println("Marks:"+marks+" Status:Fail");
}
n++;
}
}
}
Output
C:\Users\shrikanth\Desktop>java InputDemo
Marks:34.0 Status:Fail
Marks:67.0 Status:Pass
Marks:50.0 Status:Pass
Marks:49.0 Status:Fail
Marks:100.0 Status:Pass
The output format is not given so I took it as Marks:__ Status:__
Have a good day.
Get Answers For Free
Most questions answered within 1 hours.