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 / 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 |
Write a program to generate prime factors of a given integer?
What are the standard predefined macros?
how to print value of e(exp1)up to required no of digits after decimal?
What are the 4 types of organizational structures?
write a program using linked list in which each node consists of following information. Name[30] Branch Rollno Telephone no i) Write the program to add information of students in linked list
How will you write a code for accessing the length of an array without assigning it to another variable?
biggest of two no's with out using if condition statement
write a program in c language for the multiplication of two matrices using pointers?
What is wrong in this statement? scanf(“%d”,whatnumber);
sum of two integers values only other then integer it should print invalid input.
Which is not valid in C a) class aClass{public:int x;}; b) /* A comment */ c) char x=12;
What's the difference between struct x1 { ... }; and typedef struct { ... } x2; ?