Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/compat.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/compat.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/class-wp-meta-query.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/class-wp-meta-query.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/l10n.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/l10n.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/query.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/query.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/class-wp-date-query.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/class-wp-date-query.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/theme.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/theme.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/class-wp-user-query.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/class-wp-user-query.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/rewrite.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/rewrite.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/update.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/update.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/canonical.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/canonical.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/http.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/http.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/widgets/class-wp-widget-media-image.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/widgets/class-wp-widget-media-image.php on line 1
Java program to print given number in words
Java Examples Z-A All Java Codes

Java program to print given number in words

programing

package com.candidjava;
 
import java.util.Scanner;
 
public class NumberToWords
{
 
	public void pw(int n, String ch)
	{
		String one[] = { " ", " One", " Two", " Three", " Four", " Five", " Six", " Seven", " Eight", " Nine", " Ten",
				" Eleven", " Twelve", " Thirteen", " Fourteen", "Fifteen", " Sixteen", " Seventeen", " Eighteen",
				" Nineteen" };
 
		String ten[] = { " ", " ", " Twenty", " Thirty", " Forty", " Fifty", " Sixty", "Seventy", " Eighty", " Ninety" };
 
		if (n > 19)
		{
			System.out.print(ten[n / 10] + " " + one[n % 10]);
		}
		else
		{
			System.out.print(one[n]);
		}
		if (n > 0)
			System.out.print(ch);
	}
 
	public static void main(String[] args)
	{
		int n = 0;
		Scanner scanf = new Scanner(System.in);
		System.out.println("Enter an integer number: ");
		n = scanf.nextInt();
 
		if (n <= 0)
		{
			System.out.println("Enter numbers greater than 0");
		}
		else
		{
			NumberToWords a = new NumberToWords();
			a.pw((n / 1000000000), " Hundred");
			a.pw((n / 10000000) % 100, " crore");
			a.pw(((n / 100000) % 100), " lakh");
			a.pw(((n / 1000) % 100), " thousand");
			a.pw(((n / 100) % 10), " hundred");
			a.pw((n % 100), " ");
		}
	}
}
Output

Enter an integer number: 

28

Twenty  Eight 



About the author

Mathan Lal

Add Comment

Click here to post a comment