Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package edu.hdsb.rbhs.ics3u.closs.u3;
- import java.util.Scanner;
- public class NumberOfWords2 {
- public static String tens = null;
- public static String ones = null;
- public static String word = null;
- public static String teens = null;
- public static String WordInput() {
- System.out.print("Please input the number (in digits): ");
- Scanner input = new Scanner(System.in);
- word = input.nextLine();
- return word;
- }
- public static void WelcomeStatement() {
- System.out.println("This program that converts any number from 10 to 99 from its digit representation to its word representation. For example: 45 would give FORTY FIVE.\n");
- }
- public static String onesPosition() {
- if (word.charAt(1) == 1) {
- ones = "ONE ";
- } else if (word.charAt(1) == 2) {
- ones = "TWO ";
- } else if (word.charAt(1) == 3) {
- ones = "THREE ";
- } else if (word.charAt(1) == 4) {
- ones = "FOUR ";
- } else if (word.charAt(1) == 5) {
- ones = "FIVE ";
- } else if (word.charAt(1) == 6) {
- ones = "SIX ";
- } else if (word.charAt(1) == 7) {
- ones = "SEVEN ";
- } else if (word.charAt(1) == 8) {
- ones = "EIGHT ";
- } else if (word.charAt(1) == 9) {
- ones = "NINE ";
- }
- return ones;
- }
- public static String teensPosition() {
- if (word.charAt(0) == 1) {
- if (word.charAt(1) == 1) {
- teens = "ELEVEN";
- tens = " ";
- ones = " ";
- } else if (word.charAt(1) == 2) {
- teens = "TWELVE";
- tens = " ";
- ones = " ";
- } else if (word.charAt(1) == 3) {
- teens = "THIRTEEN";
- tens = " ";
- ones = " ";
- } else if (word.charAt(1) == 4) {
- teens = "FOURTEEN";
- tens = " ";
- ones = " ";
- } else if (word.charAt(1) == 5) {
- teens = "FIFTEEN";
- tens = " ";
- ones = " ";
- } else if (word.charAt(1) == 6) {
- teens = "SIXTEEN";
- tens = " ";
- ones = " ";
- } else if (word.charAt(1) == 7) {
- teens = "SEVENTEEN";
- tens = " ";
- ones = " ";
- } else if (word.charAt(1) == 8) {
- teens = "EIGHTEEN";
- tens = " ";
- ones = " ";
- } else if (word.charAt(1) == 9) {
- teens = "NINETEEN";
- tens = " ";
- ones = " ";
- }
- }
- return teens;
- }
- public static String tensPosition() {
- if (word.charAt(0) == 2) {
- tens = "TWENTY ";
- } else if (word.charAt(0) == 3) {
- tens = "THIRTY ";
- } else if (word.charAt(0) == 4) {
- tens = "FORTY ";
- } else if (word.charAt(0) == 5) {
- tens = "FIFTY ";
- } else if (word.charAt(0) == 6) {
- tens = "SIXTY ";
- } else if (word.charAt(0) == 7) {
- tens = "SEVENTY ";
- } else if (word.charAt(0) == 8) {
- tens = "EIGHTY ";
- } else if (word.charAt(0) == 9) {
- tens = "NINETY ";
- }
- return tens;
- }
- public static void main(String[] args) {
- WelcomeStatement();
- WordInput();
- onesPosition();
- tensPosition();
- teensPosition();
- System.out.print(teens + tens + ones );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement