Something went wrong. Try again.
Codelabs for major subjects in the BSIT course at STI College Meycauayan. gitlab.com/andreijiroh-dev/labs/studentops-codelab
Something went wrong. Try again.
1.3 kB · 36 lines
Java
at main
12345678910111213141516171819202122232425262728293031323334353637package dev.andreijiroh.studentops.projects;import java.util.Scanner;import java.util.InputMismatchException;
/** * 04 Laboratory Exercise * v2 - tweaked to use a while loop to re-prompt on InputMismatchException * * AI Usage Disclosure: * - Portions of code are generated with Gemini 3 Pro / 2.5 Flash Lite models via the * Google Gemini CLI in Firebase Studio (formerly Project IDX). See the chat export * archive at archive/genai-toolkit/gemini-chat-export-202603120858.md in the * project root directory. * * @author Andrei Jiroh Halili (STI College Meycauayan) <halili.459491@meycauayan.sti.edu.ph> */public class DivideDemo_v2 { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); try { int a = 10; System.out.print("Enter a integer: "); int b = keyboard.nextInt(); int result = a / b; System.out.println("Result: " + result); } catch (ArithmeticException e) { System.err.println("Can't divide by zero or something gone wrong while trying to divide"); } catch (InputMismatchException e) { System.err.println("That parameter must be a integer"); keyboard.nextLine(); } catch (Exception e) { System.err.println("Something gone wrong while running this program: "+ e); } keyboard.close(); }}