Sei sulla pagina 1di 18

package convertnum;

import java.util.Scanner;

public class convertnumtowords {

public static void main(String[] args) {

Scanner convert = new Scanner(System.in);

int enternum = 0;

// int no = enternum;

System.out.println("enter number");

enternum = convert.nextInt();

String syana = "";

String single[] = {

"zero",

"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"};

String hundred[] = {

"one hundred",

"two hundred",

"three hundred",

"four hundred",

"five hundred",

"six hundred",

"seven hundred",

"eight hundred",

"nine hundred"

};
String thousand[] = {

"one thousand",

"two thousand",

"three thousand",

"four tbousand",

"five thousand",

"six thousand",

"seven thousand",

"eight thousand",

"nine thousand",

"ten thousand",

"eleven thousand",

"twelve thousand",

"thirteen thousand",

"fourteen thousand",

"fifteen thousand",

"sixteen thousand",

"seventeen thousand",

"eighteen thousand",

"nineteen thousand",

};

String buothousand[] = {

"twenty thousand",

"thirty thousand",

"forty thousand",
"fifty thousand",

"sixy thousand",

"seventy thousand",

"eighty thousand",

"ninety thousand"

};

String tenthousand[] = {

"twenty", "thirty", "forty", "fifty ", "sixy ", "sevent ", "eighty ", "ninety "

};

String buohundredthousand[] = {

"one hundred thousand",

"two hundred thousand",

"three hundred thousand",

"four hundred thousand",

"five hundred thousand",

"six hundred thousand",

"seven hundred thousand",

"eight hundred thousand",

"nine hundred thousand",

};

String hundredthousand[] = {

"one hundred",

"two hundred ",


"three hundred ",

"four hundred ",

"five hundred ",

"six hundred ",

"seven hundred ",

"eight hundred ",

"nine hundred ",

};

String buomillion[] = {"one million"};

System.out.println(enternum + "=");

// for (enternum = 0; enternum <= 200; enternum++) {

// System.out.println(" ="+no);

// no++;

// enternum = no;

do {

if (enternum == 0) {

syana = single[0];

enternum = 0;

} else if (enternum == 1) {

syana = single[1];

enternum = 0;
} else if (enternum == 2) {

syana = single[2];

enternum = 0;

} else if (enternum == 3) {

syana = single[3];

enternum = 0;

} else if (enternum == 4) {

syana = single[4];

enternum = 0;

} else if (enternum == 5) {

syana = single[5];

enternum = 0;

} else if (enternum == 6) {

syana = single[6];

enternum = 0;

} else if (enternum == 7) {

syana = single[7];

enternum = 0;

} else if (enternum == 8) {

syana = single[8];

enternum = 0;

} else if (enternum == 9) {

syana = single[9];

enternum = 0;

} else if (enternum == 10) {


syana = single[10];

enternum = 0;

} else if (enternum == 11) {

syana = single[11];

enternum = 0;

} else if (enternum == 12) {

syana = single[12];

enternum = 0;

} else if (enternum == 13) {

syana = single[13];

enternum = 0;

} else if (enternum == 14) {

syana = single[14];

enternum = 0;

} else if (enternum == 15) {

syana = single[15];

enternum = 0;

} else if (enternum == 16) {

syana = single[16];

enternum = 0;

} else if (enternum == 17) {

syana = single[17];

enternum = 0;

} else if (enternum == 18) {

syana = single[18];
enternum = 0;

} else if (enternum == 19) {

syana = single[19];

enternum = 0;

// ten

//

//

} else if (enternum >= 20 && enternum <= 29) {

syana = ten[0];

enternum = enternum - 20;

} else if (enternum >= 30 && enternum <= 39) {

syana = ten[1];

enternum = enternum - 30;

} else if (enternum >= 40 && enternum <= 49) {

syana = ten[2];

enternum = enternum - 40;

} else if (enternum >= 50 && enternum <= 59) {

syana = ten[3];

enternum = enternum - 50;

} else if (enternum >= 60 && enternum <= 69) {

syana = ten[4];

enternum = enternum - 60;

} else if (enternum >= 70 && enternum <= 79) {


syana = ten[5];

enternum = enternum - 70;

} else if (enternum >= 80 && enternum <= 89) {

syana = ten[6];

enternum = enternum - 80;

} else if (enternum >= 90 && enternum <= 99) {

syana = ten[7];

enternum = enternum - 90;

// hundred

} else if (enternum >= 100 && enternum <= 199) {

syana = hundred[0];

enternum = enternum - 100;

} else if (enternum >= 200 && enternum <= 299) {

syana = hundred[1];

enternum = enternum - 200;

} else if (enternum >= 300 && enternum <= 399) {

syana = hundred[2];

enternum = enternum - 300;

} else if (enternum >= 400 && enternum <= 499) {

syana = hundred[3];

enternum = enternum - 400;

} else if (enternum >= 500 && enternum <= 599) {

syana = hundred[4];

enternum = enternum - 500;

} else if (enternum >= 600 && enternum <= 699) {


syana = hundred[5];

enternum = enternum - 600;

} else if (enternum >= 700 && enternum <= 799) {

syana = hundred[6];

enternum = enternum - 700;

} else if (enternum >= 800 && enternum <= 899) {

syana = hundred[7];

enternum = enternum - 800;

} else if (enternum >= 900 && enternum <= 999) {

syana = hundred[8];

enternum = enternum - 900;

// thousand

// THOUSAND

} else if (enternum >= 1000 && enternum <= 1999) {

syana = thousand[0];

enternum = enternum - 1000;

} else if (enternum >= 2000 && enternum <= 2999) {

syana = thousand[1];

enternum = enternum - 2000;

} else if (enternum >= 3000 && enternum <= 3999) {

syana = thousand[2];

enternum = enternum - 3000;

} else if (enternum >= 4000 && enternum <= 4999) {

syana = thousand[3];

enternum = enternum - 4000;


} else if (enternum >= 5000 && enternum <= 5999) {

syana = thousand[4];

enternum = enternum - 5000;

} else if (enternum >= 6000 && enternum <= 6999) {

syana = thousand[5];

enternum = enternum - 6000;

} else if (enternum >= 7000 && enternum <= 7999) {

syana = thousand[6];

enternum = enternum - 7000;

} else if (enternum >= 8000 && enternum <= 8999) {

syana = thousand[7];

enternum = enternum - 8000;

} else if (enternum >= 9000 && enternum <= 9999) {

syana = thousand[8];

enternum = enternum - 9000;

} else if (enternum >= 10000 && enternum <= 10999) {

syana = thousand[9];

enternum = enternum - 10000;

} else if (enternum >= 11000 && enternum <= 11999) {

syana = thousand[10];

enternum = enternum - 11000;

} else if (enternum >= 12000 && enternum <= 12999) {

syana = thousand[11];

enternum = enternum - 12000;


} else if (enternum >= 13000 && enternum <= 13999) {

syana = thousand[12];

enternum = enternum - 13000;

} else if (enternum >= 14000 && enternum <= 14999) {

syana = thousand[13];

enternum = enternum - 14000;

} else if (enternum >= 15000 && enternum <= 15999) {

syana = thousand[14];

enternum = enternum - 15000;

} else if (enternum >= 16000 && enternum <= 16999) {

syana = thousand[15];

enternum = enternum - 16000;

} else if (enternum >= 17000 && enternum <= 17999) {

syana = thousand[16];

enternum = enternum - 17000;

} else if (enternum >= 18000 && enternum <= 18999) {

syana = thousand[17];

enternum = enternum - 18000;

} else if (enternum >= 19000 && enternum <= 19999) {

syana = thousand[18];

enternum = enternum - 19000;

// tenthousand

//

//

} else if (enternum >= 21000 && enternum <= 29999) {


syana = tenthousand[0];

enternum = enternum - 20000;

} else if (enternum >= 31000 && enternum <= 39999) {

syana = tenthousand[1];

enternum = enternum - 30000;

} else if (enternum >= 41000 && enternum <= 49999) {

syana = tenthousand[2];

enternum = enternum - 40000;

} else if (enternum >= 51000 && enternum <= 59999) {

syana = tenthousand[3];

enternum = enternum - 50000;

} else if (enternum >= 61000 && enternum <= 69999) {

syana = tenthousand[4];

enternum = enternum - 60000;

} else if (enternum >= 71000 && enternum <= 79999) {

syana = tenthousand[5];

enternum = enternum - 70000;

} else if (enternum >= 81000 && enternum <= 89999) {

syana = tenthousand[6];

enternum = enternum - 80000;

} else if (enternum >= 91000 && enternum <= 99999) {

syana = tenthousand[7];

enternum = enternum - 90000;

}
// buotenthousand

//

//

else if (enternum >= 10000 && enternum <= 10999) {

syana = buothousand[0];

enternum = enternum - 10000;

} else if (enternum >= 20000 && enternum <= 20999) {

syana = buothousand[1];

enternum = enternum - 20000;

} else if (enternum >= 30000 && enternum <= 30999) {

syana = buothousand[2];

enternum = enternum - 30000;

} else if (enternum >= 40000 && enternum <= 40999) {

syana = buothousand[3];

enternum = enternum - 40000;

} else if (enternum >= 50000 && enternum <= 50999) {

syana = buothousand[4];

enternum = enternum - 50000;

} else if (enternum >= 60000 && enternum <= 60999) {

syana = buothousand[5];

enternum = enternum - 60000;

} else if (enternum >= 70000 && enternum <= 70999) {

syana = buothousand[6];

enternum = enternum - 70000;

} else if (enternum >= 80000 && enternum <= 80999) {


syana = buothousand[7];

enternum = enternum - 80000;

} else if (enternum >= 90000 && enternum <= 90999) {

syana = buothousand[8];

enternum = enternum - 90000;

// hundredthousand

//

//

else if (enternum >= 101000 && enternum <= 199999) {

syana = hundredthousand[0];

enternum = enternum - 100000;

} else if (enternum >= 201000 && enternum <= 299999) {

syana = hundredthousand[1];

enternum = enternum - 200000;

} else if (enternum >= 301000 && enternum <= 399999) {

syana = hundredthousand[2];

enternum = enternum - 300000;

} else if (enternum >= 401000 && enternum <= 499999) {

syana = hundredthousand[3];

enternum = enternum - 400000;

} else if (enternum >= 501000 && enternum <= 599999) {

syana = hundredthousand[4];

enternum = enternum - 500000;


} else if (enternum >= 601000 && enternum <= 699999) {

syana = hundredthousand[5];

enternum = enternum - 600000;

} else if (enternum >= 701000 && enternum <= 799999) {

syana = hundredthousand[6];

enternum = enternum - 700000;

} else if (enternum >= 801000 && enternum <= 899999) {

syana = hundredthousand[7];

enternum = enternum - 800000;

} else if (enternum >= 901000 && enternum <= 999999) {

syana = hundredthousand[8];

enternum = enternum - 900000;

// buohundrethousand

//

//

else if (enternum >= 100000 && enternum <= 100999) {

syana = buohundredthousand[0];

enternum = enternum - 100000;

} else if (enternum >= 200000 && enternum <= 200999) {

syana = buohundredthousand[1];

enternum = enternum - 200000;

} else if (enternum >= 300000 && enternum <= 300999) {

syana = buohundredthousand[2];
enternum = enternum - 300000;

} else if (enternum >= 400000 && enternum <= 400999) {

syana = buohundredthousand[3];

enternum = enternum - 400000;

} else if (enternum >= 500000 && enternum <= 500999) {

syana = buohundredthousand[4];

enternum = enternum - 500000;

} else if (enternum >= 600000 && enternum <= 600999) {

syana = buohundredthousand[5];

enternum = enternum - 600000;

} else if (enternum >= 700000 && enternum <= 700999) {

syana = buohundredthousand[6];

enternum = enternum - 700000;

} else if (enternum >= 800000 && enternum <= 800999) {

syana = buohundredthousand[7];

enternum = enternum - 800000;

} else if (enternum >= 900000 && enternum <= 900999) {

syana = buohundredthousand[8];

enternum = enternum - 900000;

} else if (enternum == 1000000) {

syana = buomillion[0];

enternum = enternum - 1000000;

System.out.println(syana);
} while (enternum != 0);

// enternum = no;

// }

// System.out.println(" ="+no);

Potrebbero piacerti anche