Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have another coding issue, using a try catch block but still getting errors an

ID: 3848829 • Letter: I

Question

I have another coding issue, using a try catch block but still getting errors and always get error: try without catch the brackets appear to be in place but still gettings errors.

public class HiLo extends javax.swing.JFrame {
    int guess = (int)(Math.random()* 101);
    int jnumber = (guess);
              

    /**
     * Creates new form HiLo
     * @param args
     */
    //@SuppressWarnings("empty-statement")
    public static void main (String[] args){
      
        System.out.println("Pick a number");
    
       try {
        System.out.println(Math.random()* 101);
        }
          (guess =>jnumber);
        
          catch {
         System.out.println("Too High, try again");
        }
          (guess <= jnumber);
          catch {
          System.out.println("Too Low, try again");
                  }
         finally (guess == True); {
      

           System.out.println("You got it, play again??");     
    }    
}     

Explanation / Answer

A try-catch block is used in Java to handle exceptions.

Exception: An exception (or exceptional event) is a problem that arises during the execution of a program. When an Exception occurs the normal flow of the program is disrupted and the program/Application terminates abnormally, which is not recommended, therefore, these exceptions are to be handled.

An exception can occur for many different reasons. Following are some scenarios where an exception occurs.

A user has entered an invalid data.

A file that needs to be opened cannot be found.

A network connection has been lost in the middle of communications or the JVM has run out of memory.

The general syntax of a try-catch block:

In your program, you did not specified type of exception that to be caught in the catch block.

I will give you the basic usage of try and catch blocks.

Ex:

Execution sequence is explained by two cases:

Some examples of Exceptions in Java:

Key Points:

Your question does not specify about what you are thinking to do.By understanding your code I guess that you should use if-else conditional blocks to get the desired output.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote