title: Getting square using try and catch
body: <p>So i'm just a grade 10 student and we were doing this program where we would get the square but it would reject negative numbers using try and catch my prof said I was the only one close to the output but ran out of time. </p>
  
  <p>this is the code.
  it displays the answer but doesnt reject negative numbers nor display "Only positive numbers"
  help pls :D</p>
  
  <pre><code>import java.util.*;
  public class MySquare{
      public static void main(String args[]){
          int num;
          int square;
  
          Scanner s = new Scanner(System.in);
          System.out.print("Input a number.");
          num = s.nextInt();
             square = num * num;
          System.out.println("Square: " + square);
          try{
  
          if( num &lt;0){
  
  
             throw new InputMismatchException("Only Positive Numbers!");
          }
      }catch (InputMismatchException e){
  
      }
  </code></pre>