0% found this document useful (0 votes)
14 views3 pages

Soal 2

The document contains code for a SOAL2 class with methods for basic arithmetic operations like addition, subtraction, multiplication and division of integers. It also contains a Sederhana method to simplify fractions. The MainSOAL2 class tests the SOAL2 class by prompting user input for numbers and calling the methods to perform calculations and display results.

Uploaded by

adsmedia140599
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views3 pages

Soal 2

The document contains code for a SOAL2 class with methods for basic arithmetic operations like addition, subtraction, multiplication and division of integers. It also contains a Sederhana method to simplify fractions. The MainSOAL2 class tests the SOAL2 class by prompting user input for numbers and calling the methods to perform calculations and display results.

Uploaded by

adsmedia140599
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

SOAL 2

SOAL 2
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package soal.pkg2;

/**
*
* @author user
*/
public class SOAL2 {
public static void Penjumlahan(int a, int b) {
int Hasil = a + b;
System.out.println("Hasil " + a + " + " + b + " = " + Hasil);
}
public static void Pengurangan(int a, int b) {
int Hasil = a - b;
System.out.println("Hasil " + a + " - " + b + " = " + Hasil);
}
public void Perkalian(int a, int b) {
int Hasil = a * b;
System.out.println("Hasil " + a + " x " + b + " = " + Hasil);
}
public void Pembagian(int a, int b) {
double Hasil = (double) a / b;
System.out.println("Hasil " + a + " : " + b + " = " + Hasil);
}
public void Sederhana(int pembilang, int penyebut) {
int s = 2, t = 2;
int a = pembilang, b = penyebut;
while (a != b) {
if (a > b) {
while ((pembilang % s) != 0) {
s++;
}
a = pembilang / s;
s++;
} else {
while ((penyebut % t) != 0) {
t++;
}
b = penyebut / t;
t++;
}
}
int pembagi = a;
int pembilang2 = pembilang / pembagi;
int penyebut2 = penyebut / pembagi;
System.out.println("Pecahan "+pembilang+"/"+penyebut+" setelah disederhanakan =
"+pembilang2+"/"+penyebut2);
}
}

MainSOAL2
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package soal.pkg2;
import java.util.Scanner;

/**
*
* @author user
*/
public class MainSOAL2 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("masukkan nilai 1 : ");
int a = in.nextInt();
System.out.print("masukkan nilai 2 : ");
int b = in.nextInt();

SOAL2.Pengurangan(a, b);
SOAL2.Penjumlahan(a, b);

SOAL2 soal = new SOAL2();


soal.Perkalian(a, b);
soal.Pembagian(a, b);

System.out.println("");
System.out.print("masukkan pembilang : ");
int c = in.nextInt();
System.out.print("masukkan penyebut : ");
int d = in.nextInt();
soal.Sederhana(c,d);

System.out.println("\nADI MASHABBI MAKSUN");


}
}

You might also like