java:exceptions_intro

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
java:exceptions_intro [2015/03/02 07:26]
gthanos
java:exceptions_intro [2015/03/02 07:50]
gthanos [Exception Handler]
Line 18: Line 18:
       int y;       int y;
       int result;       int result;
 +      Scanner input = new Scanner(System.in);​
  
       System.out.print( "Enter first integer: " );       System.out.print( "Enter first integer: " );
Line 28: Line 29:
       ​       ​
       System.out.printf( "​Product is %d\n", result );       System.out.printf( "​Product is %d\n", result );
 +   }
 } }
 </​code>​ </​code>​
Line 75: Line 77:
       int y;       int y;
       int result;       int result;
 +   Scanner input = new Scanner(System.in);​
  
       System.out.print( "Enter first integer: " );       System.out.print( "Enter first integer: " );
Line 84: Line 87:
       try {       try {
            ​result = x/y;            ​result = x/y;
 +    ​System.out.printf( "​Product is %d\n", result );
       } catch (ArithmeticException ae) {       } catch (ArithmeticException ae) {
            ​System.out.println("​ArithmeticException occured!"​);​            ​System.out.println("​ArithmeticException occured!"​);​
-           if(y = 0){ +           ​if(y ​== 0){ 
-              System.out.println("​Division by zero in particular"​)+              System.out.println("​Division by zero in particular"​);
            }            }
       }       }
-      ​ +   ​ 
-      ​System.out.printf( "​Product is %d\n", result );+   }
 } }
 </​code>​ </​code>​
java/exceptions_intro.txt · Last modified: 2019/04/20 05:02 by gthanos