| 5 | import java.util.Scanner; |
| 6 | |
| 7 | public class IntegerToWord |
| 8 | { |
| 9 | public static void main(String[] args) |
| 10 | { |
| 11 | Scanner s = new Scanner(System.in); |
| 12 | System.out.print("Enter a # (bet. -999 to 999): "); |
| 13 | int submit = s.nextInt(); // User Input |
| 14 | |
| 15 | int num = Math.abs(submit); // Turns negative input to Positive Input |
| 16 | |
| 17 | int hundreds = num / 100; // Gets the left most digit (hundreds) of the Input |
| 18 | |
| 19 | int ones = num % 10; // Gets the right most digit (ones) of the Input |
| 20 | |
| 21 | int digitMiddleRight = num % 100; // Gets the Middle digit (tens) and Right Digit (ones). |
| 22 | |
| 23 | int tens = digitMiddleRight / 10; // It is now possible to get the middle digit (tens). |
| 24 | |
| 25 | |
| 26 | if(num >= -999 && num <= 999){ // Input must be within this range. |
| 27 | if (submit < 0) // Checks if USER INPUT is negative. |
| 28 | { |
| 29 | System.out.print("Negative "); // Prints NEGATIVE. The first word if the USER INPUT is Negative. |
| 30 | } |
| 31 | else if(num == 0) // If Input is 0. then Zero |
| 32 | { |
| 33 | System.out.println("Zero"); |
| 34 | } |
| 35 | else |
| 36 | { |
| 37 | System.out.print(""); // If Input is Positive. Just leave blank. |
| 38 | } |
| 39 | |
| 40 | if(hundreds >= 1) // Remember that int hundreds was used to get the left most digit. |
| 41 | { |
| 42 | switch(hundreds) |
| 43 | { |
| 44 | case 1: System.out.print("One hundred "); break; |
| 45 | case 2: System.out.print("Two hundred "); break; |
| 46 | case 3: System.out.print("Three hundred "); break; |
| 47 | case 4: System.out.print("Four hundred "); break; |
| 48 | case 5: System.out.print("Five hundred "); break; |
| 49 | case 6: System.out.print("Six hundred "); break; |
| 50 | case 7: System.out.print("Seven hundred "); break; |
| 51 | case 8: System.out.print("Eight hundred "); break; |
| 52 | case 9: System.out.print("Nine hundred "); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | // This If-Else statement will only run if (USER_INPUT % 100) has a value. |
| 57 | |
| 58 | if(digitMiddleRight >= 11 && digitMiddleRight <= 19) // If (USER INPUT % 100) has a value between the range 11 to 19. |
| 59 | { |
| 60 | switch(digitMiddleRight) |
| 61 | { |
| 62 | case 11: System.out.print("Eleven "); break; |
| 63 | case 12: System.out.print("Twelve "); break; |
| 64 | case 13: System.out.print("Thirteen "); break; |
nothing calls this directly
no outgoing calls
no test coverage detected