Java - Angka Terbilang


Berikut Codenya Untuk pertanyaan silakan hubungi mafifannisa@gmail.com atau kunjungi afifannisa.ddns.net
Untuk Download Klik Link dibawah ini dan buka dengan Netbean

Model Sedikit Ribet :

/*
 * 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 ngka.terbilang;

import java.util.Scanner;

/**
 *
 * @author Moch.Afif
 */
public class NgkaTerbilang {
    String[] angka={"","Satu","Dua","Tiga","Empat","Lima","Enam",
                         "Tujuh","Delapan","Sembilan","Sepuluh","Sebelas"};
    public String kata(double ank){
        if(ank<1){
            return "Nol";
        }
        if(ank<12)
        {
          return angka[(int)ank];
        }
        
        return "";              
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        double a;
        Scanner input = new Scanner (System.in);
        System.out.print("Masukan Angka : ");
        a=input.nextDouble();
        System.out.println( "Terbilang : "+new NgkaTerbilang().kata(a));
    }
    
}


Model Sedikit Mudah :

/*
 * 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 angkaterbilangmax10;

import java.util.Scanner;

/**
 *
 * @author Moch.Afif
 */
public class Angkaterbilangmax10 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        String[] angka={"nol","Satu","Dua","Tiga","Empat","Lima","Enam",
                         "Tujuh","Delapan","Sembilan"};
        Scanner in = new Scanner(System.in);
        int a ;
        System.out.print("Masukan Anga : ");
        a=in.nextInt();
        if(a<10){
            System.out.print("Terbilang : "+angka[a]);
            System.out.println("");
        }else{System.out.println("Angka Lebh Dari 1 Digit");}
    }
    
}


Model Lumayan Ribet 0 - 1jt :

/*
 * 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 ngka.terbilang;

import java.util.Scanner;

/**
 *
 * @author Moch.Afif
 */
public class NgkaTerbilang {
    String[] angka={"","Satu","Dua","Tiga","Empat","Lima","Enam",
                         "Tujuh","Delapan","Sembilan","Sepuluh","Sebelas"};
    public String kata(double ank){
        
        if(ank<12)
        {
          return angka[(int)ank];
        }
         if(ank>=12 && ank <=19)
        {
            return angka[(int)ank%10] +" Belas ";
        }
        
        if(ank>=20 && ank <=99)
        {
            return angka[(int)ank/10] +" Puluh "+angka[(int)ank%10];
        }
        
        if(ank>=100 && ank <=199)
        {
            return "Seratus "+ kata(ank%100);
        }
        
        if(ank>=200 && ank <=999)
        {
            return angka[(int)ank/100]+" Ratus "+kata(ank%100);
        }
        
        if(ank>=1000 && ank <=1999)
        {
            return "Seribu "+ kata(ank%1000);
        }
        
        if(ank >= 2000 && ank <=999999)
        {
            return kata((int)ank/1000)+" Ribu "+ kata(ank%1000);
        }
        
        if(ank >= 1000000 && ank <=999999999)
        {
            return kata((int)ank/1000000)+" Juta "+ kata(ank%1000000);
        }
        return "";              
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        double a;
        Scanner input = new Scanner (System.in);
        System.out.print("Masukan Angka : ");
        a=input.nextDouble();
        if (a==0){
            System.out.println("Terbilang : Nol");
        }else{
            System.out.println( "Terbilang : "+new NgkaTerbilang().kata(a));
        }
        
    }
    
}

Comments

Popular posts from this blog

VB.NET - Membuat Angka Acak

Kenapa dinamai windows?

Java - Metode Numerik Metode Bagi Dua