Advertisement
Guest User

Kisi-Kisi Java - For & IF

a guest
Jan 16th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.66 KB | None | 0 0
  1.  
  2. /*
  3.  * To change this license header, choose License Headers in Project Properties.
  4.  * To change this template file, choose Tools | Templates
  5.  * and open the template in the editor.
  6.  */
  7. import java.util.Scanner;
  8. /**
  9.  *
  10.  * @author runsel
  11.  */
  12. public class c_tes {
  13.  
  14.     /**
  15.      * @param args the command line arguments
  16.      */
  17.     public static void main(String[] args) {
  18.         //Tampilkan menu untuk user
  19.         System.out.println("Pilih program : ");
  20.         System.out.println("1. Konversi KM ke M");
  21.         System.out.println("2. Konversi KM ke CM");
  22.        
  23.         Scanner input = new Scanner(System.in);
  24.         //Terima pilihan menu dari user
  25.         System.out.print("Pilihan anda : ");
  26.        
  27.         int pilihan = input.nextInt();
  28.        
  29.         //Terima input batas awal
  30.         System.out.print("Masukkan batas awal : ");
  31.         int awal = input.nextInt();
  32.        
  33.         //Terima input batas akhir
  34.         System.out.print("Masukkan batas akhir : ");
  35.         int akhir = input.nextInt();
  36.        
  37.         for(int data=awal; data<=akhir; data++){
  38.             if(pilihan == 1){
  39.                 int output = data*1000;
  40.                 //Tampilkan hasil
  41.                 //Output : 2 Kilometer = 20000 Meter
  42.                 System.out.print(data+" Kilometer ");
  43.                 System.out.println(output+" Meter");
  44.             }else if(pilihan == 2){
  45.                 int output = data*100000;
  46.                 //Tampilkan hasil
  47.                 //Output : 2 Kilometer = 20000 Centimeter
  48.                 System.out.print(data+" Kilometer ");
  49.                 System.out.println(output+" Centimeter");
  50.             }
  51.         }
  52.     }
  53.    
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement