0% found this document useful (0 votes)
54 views

Contoh Program Java: Tugas

The document provides a Java program example that takes input of two numbers x and y from the user, displays options for addition, subtraction, multiplication and division, takes the user's choice, performs the selected mathematical operation on x and y and displays the result. It uses a switch statement and catches exceptions for invalid input. The task is to run the program, then write an official report with the Java settings procedure, compilation steps and analysis of why some parts may not run correctly.

Uploaded by

pojok
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views

Contoh Program Java: Tugas

The document provides a Java program example that takes input of two numbers x and y from the user, displays options for addition, subtraction, multiplication and division, takes the user's choice, performs the selected mathematical operation on x and y and displays the result. It uses a switch statement and catches exceptions for invalid input. The task is to run the program, then write an official report with the Java settings procedure, compilation steps and analysis of why some parts may not run correctly.

Uploaded by

pojok
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 1

CONTOH PROGRAM JAVA

package contoh1; import java.io.*; public class Main { public static void main(String[] args) throws Exception{ // TODO code application logic here //int x, y; BufferedReader object = new BufferedReader (new InputStreamReader(System.in)); try{ System.out.print("Input X:"); int x = Integer.parseInt(object.readLine()); System.out.print("Input Y:"); int y = Integer.parseInt(object.readLine()); System.out.println("1. Penjumlahan"); System.out.println("2. Pengurangan"); System.out.println("3. Perkalian"); System.out.println("4. Pembagian"); System.out.print("Pilihan:"); int a = Integer.parseInt(object.readLine()); switch (a){ case 1: System.out.println("Memasukkan nomer satu=" + (x+y)); break; case 2: System.out.println("Memasukkan nomer dua =" + (x-y)); break; case 3: System.out.println("Memasukkan nomer tiga ="+ (x*y)); break; case 4: System.out.println("Memasukkan nomer empat ="+ (x/y)); break; default: System.out.println("Masukkan salah!"); } } catch(NumberFormatException ne){ System.out.println(ne.getMessage() + "Input Salah..!"); System.exit(0); } } }

TUGAS: Kerjakan program diatas, kemudian buatlah Laporan Resmi untuk dikumpulkan minggu depan berisi prosedur Seting Java, cara kompilasi, dan analisa program : mengapa ada beberapa masih salah/tidak jalan.

You might also like