Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does this code cause an "illegal start of expression" exception?
    primarykey
    data
    text
    <p>These are my questions:</p> <ol> <li><p>I'm getting a couple of errors on the line "public static boolean validNumCheck(String num){" - "illegal start of expression", "';' expected", and "')' expected".</p></li> <li><p>How can I give the user 3 tries in total for each number? I believe right now the programme asks the user for 3 numbers and gives them 3 tries in total to get the numbers correct (My explanations suck... read the code to get a better idea of what I mean).</p></li> </ol> <p>This is my code:</p> <pre><code>import javax.swing.JOptionPane; public class Assignment3 { public static void main (String[] args){ final int MAX_TRIES = 3; int[] attempts= new int[2]; String[] getNumber= new String [2]; //Ask the user for 3 integers. while(attempts[0]&lt;MAX_TRIES){ getNumber[0]= JOptionPane.showInputDialog(null,"Please enter an integer between 0-200."); //Pass the value to validNumChek validNumCheck (getNumber); //If it is not a valid number give the user 3 more tries. if (getNumber== false){ while(attempts[1]&lt;MAX_TRIES){ getNumber[1]= JOptionPane.showInputDialog(null,"Please enter an integer between 0-200."); attempts[1]++;} } attempts[0]++; } //Parse the string to an integer and check if it is a valid number. public static boolean validNumCheck(String num){ int number; try { number = Integer.parseInt(num); return number &gt;= 0 &amp;&amp; number &lt;= 200; }catch(NumberFormatException e){ //If it is not a valid number return false. return false; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload