Advertisement
Guest User

1-999

a guest
Apr 6th, 2020
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.53 KB | None | 0 0
  1. /******************************************************************************
  2.  
  3.                             Online Java Compiler.
  4.                 Code, Compile, Run and Debug java program online.
  5. Write your code in this editor and press "Run" button to execute it.
  6.  
  7. *******************************************************************************/
  8. import java.util.Scanner;  // Import the Scanner class
  9. public class Main
  10. {
  11.     public static void main(String[] args) {
  12.         Scanner reader = new Scanner(System.in);
  13.         System.out.print("Masukkan bilangan: ");
  14.         int num = reader.nextInt();
  15.         String output = "";
  16.        
  17.         if (num >= 100 && num <= 999)
  18.         {
  19.             int hundreds = num / 100;
  20.             if (hundreds == 1)
  21.             {
  22.                 output += "seratus ";
  23.             } else if (hundreds == 2)
  24.             {
  25.                 output += "dua ratus ";
  26.             } else if (hundreds == 3)
  27.             {
  28.                 output += "tiga ratus ";
  29.             } else if (hundreds == 4)
  30.             {
  31.                 output += "empat ratus ";
  32.             } else if (hundreds == 5)
  33.             {
  34.                 output += "lima ratus ";
  35.             } else if (hundreds == 6)
  36.             {
  37.                 output += "enam ratus ";
  38.             } else if (hundreds == 7)
  39.             {
  40.                 output += "tujuh ratus ";
  41.             } else if (hundreds == 8)
  42.             {
  43.                 output += "delapan ratus ";
  44.             } else if (hundreds == 9)
  45.             {
  46.                 output += "sembilan ratus ";
  47.             }
  48.         }
  49.        
  50.         num = num % 100;
  51.        
  52.         if (num >= 10 && num <= 99)
  53.         {
  54.             // 10 - 19
  55.             if (num == 10)
  56.             {
  57.                 output = "sepuluh";
  58.             } else if (num == 11)
  59.             {
  60.                 output += "sebelas";
  61.             } else if (num == 12)
  62.             {
  63.                 output += "dua belas";
  64.             } else if (num == 13)
  65.             {
  66.                 output += "tiga belas";
  67.             } else if (num == 14)
  68.             {
  69.                 output += "empat belas";
  70.             } else if (num == 15)
  71.             {
  72.                 output += "lima belas";
  73.             } else if (num == 16)
  74.             {
  75.                 output += "enam belas";
  76.             } else if (num == 17)
  77.             {
  78.                 output += "tujuh belas";
  79.             } else if (num == 18)
  80.             {
  81.                 output += "delapan belas";
  82.             } else if (num == 19)
  83.             {
  84.                 output += "sembilan belas";
  85.             }
  86.             // 20 - 99
  87.             else
  88.             {
  89.                 int num_copy = num / 10;
  90.                 if (num_copy == 2)
  91.                 {
  92.                     output += "dua";
  93.                 } else if (num_copy == 3)
  94.                 {
  95.                     output += "tiga";
  96.                 } else if (num_copy == 4)
  97.                 {
  98.                     output += "empat";
  99.                 } else if (num_copy == 5)
  100.                 {
  101.                     output += "lima";
  102.                 } else if (num_copy == 6)
  103.                 {
  104.                     output += "enam";
  105.                 } else if (num_copy == 7)
  106.                 {
  107.                     output += "tujuh";
  108.                 } else if (num_copy == 8)
  109.                 {
  110.                     output += "delapan";
  111.                 } else if (num_copy == 9)
  112.                 {
  113.                     output += "sembilan";
  114.                 }
  115.                 output += " puluh ";
  116.                 num = num % 10;
  117.             }
  118.         }
  119.        
  120.        
  121.        
  122.         if (num >= 1 && num <= 9)
  123.         {
  124.             if (num == 1)
  125.             {
  126.                 output += "satu";
  127.             } else if (num == 2)
  128.             {
  129.                 output += "dua";
  130.             } else if (num == 3)
  131.             {
  132.                 output += "tiga";
  133.             } else if (num == 4)
  134.             {
  135.                 output += "empat";
  136.             } else if (num == 5)
  137.             {
  138.                 output += "lima";
  139.             } else if (num == 6)
  140.             {
  141.                 output += "enam";
  142.             } else if (num == 7)
  143.             {
  144.                 output += "tujuh";
  145.             } else if (num == 8)
  146.             {
  147.                 output += "delapan";
  148.             } else if (num == 9)
  149.             {
  150.                 output += "sembilan";
  151.             }
  152.         }
  153.         // System.out.println(num);
  154.         System.out.println("Terbilang : " + output);
  155.     }
  156. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement