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 |
writ a program to compare using strcmp VIVA and viva with its output.
Write a program to replace n bits from the position p of the bit representation of an inputted character x with the one's complement. Method invertBit takes 3 parameters x as input character, p as position and n as the number of positions from p. Replace n bits from pth position in 8 bit character x. Then return the characters by inverting the bits.
can u write a program in C, which does not use = (eqaul)or any arithmatic assignment(like -=,+=,*= etc) operator to swap to number?
Where does the name "C" come from, anyway?
What is the proper way of these job Tell me about there full work
If the size of int data type is two bytes, what is the range of signed int data type?
Explain what is dynamic data structure?
what is computer
Is c dynamically typed?
What's the difference between a linked list and an array?
Write a program for deleting duplicate elements in an array
#define FALSE -1 #define TRUE 1 #define NULL 0 main() { if(NULL) puts("NULL"); else if(FALSE) puts("TRUE"); else puts("FALSE"); }