Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /******************************************************************************
- Online Java Compiler.
- Code, Compile, Run and Debug java program online.
- Write your code in this editor and press "Run" button to execute it.
- *******************************************************************************/
- import java.util.Scanner; // Import the Scanner class
- public class Main
- {
- public static void main(String[] args) {
- Scanner reader = new Scanner(System.in);
- System.out.print("Masukkan bilangan: ");
- int num = reader.nextInt();
- String output = "";
- if (num >= 100 && num <= 999)
- {
- int hundreds = num / 100;
- if (hundreds == 1)
- {
- output += "seratus ";
- } else if (hundreds == 2)
- {
- output += "dua ratus ";
- } else if (hundreds == 3)
- {
- output += "tiga ratus ";
- } else if (hundreds == 4)
- {
- output += "empat ratus ";
- } else if (hundreds == 5)
- {
- output += "lima ratus ";
- } else if (hundreds == 6)
- {
- output += "enam ratus ";
- } else if (hundreds == 7)
- {
- output += "tujuh ratus ";
- } else if (hundreds == 8)
- {
- output += "delapan ratus ";
- } else if (hundreds == 9)
- {
- output += "sembilan ratus ";
- }
- }
- num = num % 100;
- if (num >= 10 && num <= 99)
- {
- // 10 - 19
- if (num == 10)
- {
- output = "sepuluh";
- } else if (num == 11)
- {
- output += "sebelas";
- } else if (num == 12)
- {
- output += "dua belas";
- } else if (num == 13)
- {
- output += "tiga belas";
- } else if (num == 14)
- {
- output += "empat belas";
- } else if (num == 15)
- {
- output += "lima belas";
- } else if (num == 16)
- {
- output += "enam belas";
- } else if (num == 17)
- {
- output += "tujuh belas";
- } else if (num == 18)
- {
- output += "delapan belas";
- } else if (num == 19)
- {
- output += "sembilan belas";
- }
- // 20 - 99
- else
- {
- int num_copy = num / 10;
- if (num_copy == 2)
- {
- output += "dua";
- } else if (num_copy == 3)
- {
- output += "tiga";
- } else if (num_copy == 4)
- {
- output += "empat";
- } else if (num_copy == 5)
- {
- output += "lima";
- } else if (num_copy == 6)
- {
- output += "enam";
- } else if (num_copy == 7)
- {
- output += "tujuh";
- } else if (num_copy == 8)
- {
- output += "delapan";
- } else if (num_copy == 9)
- {
- output += "sembilan";
- }
- output += " puluh ";
- num = num % 10;
- }
- }
- if (num >= 1 && num <= 9)
- {
- if (num == 1)
- {
- output += "satu";
- } else if (num == 2)
- {
- output += "dua";
- } else if (num == 3)
- {
- output += "tiga";
- } else if (num == 4)
- {
- output += "empat";
- } else if (num == 5)
- {
- output += "lima";
- } else if (num == 6)
- {
- output += "enam";
- } else if (num == 7)
- {
- output += "tujuh";
- } else if (num == 8)
- {
- output += "delapan";
- } else if (num == 9)
- {
- output += "sembilan";
- }
- }
- // System.out.println(num);
- System.out.println("Terbilang : " + output);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement