How much money do you have?
package com.gmail.vhrushyn;
import java.util.Scanner;
public class main {
public static void main(String[] args) {
System.out.println("How much money do you have?");
Scanner sc = new Scanner(System.in);
double moneyD = sc.nextDouble();
moneyD = moneyD * 100.0;
// double to long array which contains 11 digits (9 digits for 999 999 999 dollars + 2 digits for 99) cents
long moneyL = ((long) moneyD);
String moneyS = Long.toString(moneyL);
int length = moneyS.length();
long[] moneySh = new long[length];
moneySh[0] = (long) (moneyL / (Math.pow(10, length - 1)));
for (int i = 1; i < length - 1; i++) {
moneySh[i] = (long) (moneyL % (Math.pow(10, length - i))) / (long)(Math.pow(10, length - (i + 1)));
}
moneySh[length-1] = moneyL % 10;
int[] money = new int[11];
for (int i = 0; i < 11 - length; i++) {
money[i] = 0;
}
int j = 0;
for (int i = 11 - length; i < 11; i++) {
money[i] = (int) moneySh[j];
j++;
}
sc.close();
// word equals of digits
String[] w1 = new String[10];
w1[0] = "";
w1[1] = "one ";
w1[2] = "two ";
w1[3] = "three ";
w1[4] = "four ";
w1[5] = "five ";
w1[6] = "six ";
w1[7] = "seven ";
w1[8] = "eight ";
w1[9] = "nine ";
String[] w2 = new String[10];
w2[0] = "ten ";
w2[1] = "eleven ";
w2[2] = "twelve ";
w2[3] = "thirteen ";
w2[4] = "fourteen ";
w2[5] = "fifteen ";
w2[6] = "sixteen ";
w2[7] = "seventeen ";
w2[8] = "eighteen ";
w2[9] = "nineteen ";
String[] w10 = new String[10];
w10[0] = "";
w10[1] = "ten ";
w10[2] = "twenty ";
w10[3] = "thirty ";
w10[4] = "fourty ";
w10[5] = "fifty ";
w10[6] = "sixty ";
w10[7] = "seventy ";
w10[8] = "eighty ";
w10[9] = "ninety ";
// preparatory filling the output string array
String[] p = new String[11];
for (int i = 0; i < 11; i++) {
p[i] = "";
}
// filling the output string array
for (int i = 0; i < 11; i++) {
for (j = 0; j < 10; j++) {
if (money[i] == j) {
p[i] = w1[j];
break;
}
}
}
if (money[10] == 0 && money[9] == 0) {
p[10] = "zero ";
p[9] = "";
}
if (money[9] == 1) {
for (j = 0; j < 10; j++) {
if (money[10] == j) {
p[9] = w2[j];
p[10] = "";
break;
}
}
}
if (money[9] == 0 && money[10] != 0) {
for (j = 0; j < 10; j++) {
if (money[10] == j) {
p[10] = w1[j];
p[9] = "";
break;
}
}
}
if (money[9] != 0 && money[9] != 1) {
for (j = 0; j < 10; j++) {
if (money[9] == j) {
p[9] = w10[j];
break;
}
}
}
if (money[8] == 0 && money[7] == 0 && money[6] == 0 && money[5] == 0 && money[4] == 0 && money[3] == 0 && money[2] == 0 && money[1] == 0 && money[0] == 0) {
for (j = 0; j < 10; j++) {
if (money[8] == j) {
p[8] = "no any ";
}
}
}
if (money[8] != 0) {
for (j = 0; j < 10; j++) {
if (money[8] == j) {
p[8] = w1[j];
// p[7] = "";
break;
}
}
}
if (money[7] == 0) {
for (j = 0; j < 10; j++) {
if (money[7] == j) {
p[7] = w1[j];
// p[7] = "";
break;
}
}
}
if (money[7] == 1 && money[8] != 0) {
for (j = 0; j < 10; j++) {
if (money[8] == j) {
p[7] = "";
p[8] = w2[j];
break;
}
}
}
if (money[7] == 1 && money[8] == 0) {
for (j = 0; j < 10; j++) {
if (money[7] == j) {
p[7] = w2[j - 1];
p[8] = "";
break;
}
}
}
if (money[7] != 0 && money[7] != 1) {
for (j = 0; j < 10; j++) {
if (money[7] == j) {
p[7] = w10[j];
break;
}
}
}
if (money[6] == 0) {
p[6] = "";
}
if (money[6] != 0) {
for (j = 0; j < 10; j++) {
if (money[6] == j) {
p[6] = w1[j]+"hundred ";
break;
}
}
}
if (money[5] == 0) {
p[5] = "";
}
if (money[5] != 0) {
for (j = 0; j < 10; j++) {
if (money[5] == j) {
p[5] = w1[j]+"thousand ";
break;
}
}
}
if (money[4] == 0) {
for (j = 0; j < 10; j++) {
if (money[4] == j) {
p[4] = "";
}
}
}
if (money[4] == 1) {
for (j = 0; j < 10; j++) {
if (money[5] == j) {
p[5] = w2[j]+ "thousand ";
break;
}
}
}
if (money[4] != 0 && money[4] != 1) {
for (j = 0; j < 10; j++) {
if (money[4] == j) {
p[4] = w10[j];
break;
}
}
}
if (money[3] == 0) {
p[3] = "";
}
if (money[3] != 0) {
for (j = 0; j < 10; j++) {
if (money[3] == j) {
p[3] = w1[j]+"hundred ";
break;
}
}
}
if (money[3] != 0 && money[5] == 0) {
for (j = 0; j < 10; j++) {
if (money[3] == j) {
p[3] = w1[j]+"hundred thousand ";
break;
}
}
}
if (money[2] == 0) {
p[2] = "";
}
if (money[2] != 0) {
for (j = 0; j < 10; j++) {
if (money[2] == j) {
p[2] = w1[j]+"million ";
break;
}
}
}
if (money[1] == 0) {
for (j = 0; j < 10; j++) {
if (money[1] == j) {
p[1] = "";
}
}
}
if (money[1] == 1) {
for (j = 0; j < 10; j++) {
if (money[1] == j) {
p[1] = w2[j]+ "million ";
break;
}
}
}
if (money[1] != 0 && money[1] != 1) {
for (j = 0; j < 10; j++) {
if (money[1] == j) {
p[1] = w10[j];
break;
}
}
}
if (money[0] == 0) {
p[0] = "";
}
if (money[0] != 0) {
for (j = 0; j < 10; j++) {
if (money[0] == j) {
p[0] = w1[j]+"hundred ";
break;
}
}
}
if (money[0] != 0 && money[2] == 0) {
for (j = 0; j < 10; j++) {
if (money[0] == j) {
p[0] = w1[j]+"hundred million ";
break;
}
}
}
String pt = p[0]+p[1]+p[2]+p[3]+p[4]+p[5]+p[6]+p[7]+p[8]+"dollars "+p[9]+p[10]+"cents";
System.out.print("You have: ");
System.out.println(pt);
}
}