CS JAVA question this is what is done so far and I am trying to make conditions
ID: 3755728 • Letter: C
Question
CS JAVA question
this is what is done so far and I am trying to make conditions by usint while try catch matheod.
the user input have to be bigger than 0 and if not the error message have to show and user need to make another input
also, if input == null --> if user cancel then program should stop.
if everything is good than the program should run.
I have method to return and more steps that I need to do but I just need a really good example to use while try catch in this situation.
please help me
String input; boolean progFfalse; input = JOptionPane·showinputDialog ("put number 0 or bigger"); int level Integer.valueOf (input);Explanation / Answer
package weiss.util; import javax.swing.*; public class ValidateStringInput { public static void main(String[] args) { String input; boolean progF = false; int level; while (true) { try { input = JOptionPane.showInputDialog("Put number 0 or bigger"); level = Integer.parseInt(input); if(level >= 0) { break; } else { JOptionPane.showMessageDialog(null, "Error. Please enter a number 0 or bigger!"); } } catch (Exception e) { JOptionPane.showMessageDialog(null, "Error. Please enter an integer only!"); } } // Enter your rest of the code here. } }