summary refs log tree commit diff stats
path: root/java/code
diff options
context:
space:
mode:
authorSudipto Mallick <smlckz@termux-alpine>2024-01-27 11:33:43 +0000
committerSudipto Mallick <smlckz@termux-alpine>2024-01-27 11:34:11 +0000
commitcd6a9243c056710794549a1ab5d51fbdd082ce2e (patch)
treef3f4df42bcfa96b9d6ef48da2b33be148adfdd2b /java/code
parent1db2841d10c6920eba89f1e55eb3c90aa770ad07 (diff)
downloadzadania-cd6a9243c056710794549a1ab5d51fbdd082ce2e.tar.gz
Complete Java assignments #7-13
Diffstat (limited to 'java/code')
-rw-r--r--java/code/ShapeAreaCalculations.java10
1 files changed, 7 insertions, 3 deletions
diff --git a/java/code/ShapeAreaCalculations.java b/java/code/ShapeAreaCalculations.java
index 0d00bff..ca20d39 100644
--- a/java/code/ShapeAreaCalculations.java
+++ b/java/code/ShapeAreaCalculations.java
@@ -1,4 +1,5 @@
 import java.util.Scanner;
+import java.util.InputMismatchException;
 
 class Shape {
     // Calculates the area of a triangle.
@@ -20,11 +21,11 @@ class Shape {
     }
 }
 
-class AreaCalc {
+class ShapeAreaCalculations {
     public static void main(String args[]) {
-        var sc = new Scanner(System.in);
+	try (var sc = new Scanner(System.in)) {
         System.out.println("Choose the shape: ");
-        System.out.println("1. Triangle\n2. Rectangle\n3. Square\n4.Circle");
+        System.out.println("1. Triangle\n2. Rectangle\n3. Square\n4. Circle");
         System.out.print("Enter your choice: ");
         var choice = sc.nextInt();
         switch (choice) {
@@ -55,5 +56,8 @@ class AreaCalc {
                 System.out.println("Invalid choice");
                 break;
         }
+	} catch (InputMismatchException e) {
+            System.err.println("Invalid number given as input");
+        }
     }
 }