Thursday, November 16, 2017

Contoh kalkulator Sederhana

Salam Sarjana || Saya akan membahas materi Pemrograman Java tentang Contoh Program  Sederhana  "Kalulator", baiklah marilah kita bahas.




  

package kalkulatorsederhana;

import java.util.Scanner;

public class KalkulatorSederhana {

    public static void main(String[] args) {
        // Deklarasi Variabel
        int inputan1, inputan2, inputan3, inputan4;
        int tambah, kurang;
        float bagi, kali, modulus;
        String nama, NPM;
        
        // Inputan
        Scanner input = new Scanner(System.in);
        System.out.println("INPUT");
        System.out.println("========================");
        System.out.print("Masukan Nama Anda : ");
        nama = input.nextLine();
        System.out.print("Masukan NPM Anda  : ");
        NPM = input.nextLine();
        System.out.print("Masukan Nilai 1   : ");
        inputan1 = input.nextInt();
        System.out.print("Masukan Nilai 2   : ");
        inputan2 = input.nextInt();
        System.out.println("========================");
        
        // Proses
        tambah = inputan1 + inputan2;
        kurang = inputan1 - inputan2;
        kali = inputan1 * inputan2;
        bagi = inputan1 / inputan2;
        modulus = inputan1 % inputan2;
        
        System.out.println("\n");
        System.out.println("OUTPUT");
        System.out.println("========================");
        System.out.println("Nama Anda Adalah    : " + nama);
        System.out.println("NPM Anda Adalah     : " + NPM);
        System.out.println("Hasil Penjumlahan   : " + tambah);
        System.out.println("Hasil Pengurangan   : " + kurang);
        System.out.println("Hasil Pengkalian    : " + kali);
        System.out.println("Hasil Pembagian     : " + bagi);
        System.out.println("Hasil Modulus       : " + modulus);
        System.out.println("========================");
    }
    
}

}








Hasilnya :



No comments:
Write comments