write a program to read a number and print in words that is
in sentence for example 21,219 then output is "twenty one
thousand and two hundred nineteen" by using only control
flow statements (only loops and switch case )?

Answer Posted / anil kumar

import java.util.Scanner;


public class numberFormat
{
public static void main(String[] args)
{
Scanner s=new Scanner(System.in);
System.out.println("Enter 4 digit number : ");
int num=s.nextInt();
int a=num;

a=num/1000;

if(a==1)
System.out.println("One thousand");
else if(a==2)
System.out.println("Two thousand");
else if(a==3)
System.out.println("Three thousand");
else if(a==4)
System.out.println("Four thousand");
else if(a==5)
System.out.println("Five thousand");
else if(a==6)
System.out.println("Six thousand");
else if(a==7)
System.out.println("Seven thousand");
else if(a==8)
System.out.println("Eight thousand");
else if(a==9)
System.out.println("Nine thousand");
int first=num-a*1000;

int y=first/100;

if(y==1)
System.out.println("One hundred");
else if(y==2)
System.out.println("Two hundred");
else if(y==3)
System.out.println("Three hundred");
else if(y==4)
System.out.println("Four hundred");
else if(y==5)
System.out.println("Five hundred");
else if(y==6)
System.out.println("Six hundred");
else if(y==7)
System.out.println("Seven hundred");
else if(y==8)
System.out.println("Eight hundred");
else if(y==9)
System.out.println("Nine hundred");
int second=first-y*100;

int x=second/10;
if(x==1)
System.out.println("Ten");
else if(x==2)
System.out.println("Twenty");
else if(x==3)
System.out.println("Thirty");
else if(x==4)
System.out.println("Fourty");
else if(x==5)
System.out.println("Fifty");
else if(x==6)
System.out.println("Sixty");
else if(x==7)
System.out.println("Seventy");
else if(x==8)
System.out.println("Eighty");
else if(x==9)
System.out.println("Ninty");
int third=second-x*10;



int z=third;

if (z==2)
System.out.println(" two");
else if (z==3)
System.out.println(" three");
else if (z==4)
System.out.println(" four");
else if (z==5)
System.out.println(" five");
else if (z==6)
System.out.println(" six");
else if (z==7)
System.out.println(" seven");
else if (z==8)
System.out.println(" eight");
else if (z==9)
System.out.println(" nine");



}

}



use switch case in case of if condition you will get it.

Is This Answer Correct ?    3 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is 02d in c?

634


What is a pointer in c plus plus?

690


please help me..... please codes and flowchart plz turbo c lang po yan.....please asap response... 3. Make an astrology program. The user types in his or her birthday (month, day, and year as integer), and the program responds with the user’s zodiac sign, horoscope, and other information related to it. If the user’s birth year falls into a leap year, your program should display an appropriate message for it. NOTES: Conditional Statements: it should be with graphics

2854


Calculate the weighted average of a list of n numbers using the formula xavg = f1x1+f2x2+ ….+ fnxn where the f’s are fractional weighting factors, i.e., 0<=fi<1, and f1+f2+….+fn = 1

3651


What is the difference between int main and void main in c?

589






What is string length in c?

605


How can I find out if there are characters available for reading?

640


What are the rules for identifiers in c?

582


What is the use of ?: Operator?

661


pierrot's divisor program using c or c++ code

1724


What is the advantage of an array over individual variables?

734


c language supports bitwise operations, why a) 'c' language is system oriented b) 'c' language is problem oriented c) 'c' language is middle level language d) all the above

608


What is adt in c programming?

607


How can I implement a delay, or time a users response, with sub-second resolution?

617


An expression to whose value an operater is applied a) operand b) variable c) constant d) all of the above

654