Advertisement
Guest User

Working Code.

a guest
Oct 14th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.23 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3.  
  4. public class Lab09
  5. {
  6.    public static void main(String[] args) throws FileNotFoundException
  7.    {
  8.       String strInput = "", strOut = "", number = "";
  9.       int length;
  10.       char ch;
  11.      
  12.       File myFile = new File("input.txt");
  13.       Scanner inputFile = new Scanner(myFile);
  14.      
  15.       while (inputFile.hasNext()) {
  16.          strInput = inputFile.nextLine();
  17.          length = strInput.length();
  18.          for (int i = 0; i < length; i++) {
  19.             ch = strInput.charAt(i);
  20.             if (Character.isUpperCase(ch)) {
  21.                ch = Character.toLowerCase(ch);
  22.             }
  23.             else if (Character.isLowerCase(ch)) {
  24.                ch = Character.toUpperCase(ch);
  25.             }
  26.             else if (ch >= '0' && ch <= '9') {
  27.                switch (ch) {
  28.                   case '0':
  29.                      number = "zero";
  30.                      break;
  31.                   case '1':
  32.                      number = "one";
  33.                      break;
  34.                   case '2':
  35.                      number = "two";
  36.                      break;
  37.                   case '3':
  38.                      number = "three";
  39.                      break;
  40.                   case '4':
  41.                      number = "four";
  42.                      break;
  43.                   case '5':
  44.                      number = "five";
  45.                      break;
  46.                   case '6':
  47.                      number = "six";
  48.                      break;
  49.                   case '7':
  50.                      number = "seven";
  51.                      break;
  52.                   case '8':
  53.                      number = "eight";
  54.                      break;
  55.                   case '9':
  56.                      number = "nine";
  57.                      break;
  58.                }
  59.                if (i <= length) {
  60.                   strOut += number;
  61.                   if (i < strInput.length()-1 && strInput.charAt(i+1) >= '0' && strInput.charAt(i+1) <= '9') {
  62.                      strOut += "-";
  63.                   }
  64.                }
  65.             }
  66.             if (ch < '0' || ch > '9')
  67.                strOut += ch;
  68.          }
  69.       System.out.println(strOut);
  70.       strOut = "";
  71.       }
  72.       inputFile.close();
  73.    }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement