Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- public class Lab09
- {
- public static void main(String[] args) throws FileNotFoundException
- {
- String strInput = "", strOut = "", number = "";
- int length;
- char ch;
- File myFile = new File("input.txt");
- Scanner inputFile = new Scanner(myFile);
- while (inputFile.hasNext()) {
- strInput = inputFile.nextLine();
- length = strInput.length();
- for (int i = 0; i < length; i++) {
- ch = strInput.charAt(i);
- if (Character.isUpperCase(ch)) {
- ch = Character.toLowerCase(ch);
- }
- else if (Character.isLowerCase(ch)) {
- ch = Character.toUpperCase(ch);
- }
- else if (ch >= '0' && ch <= '9') {
- switch (ch) {
- case '0':
- number = "zero";
- break;
- case '1':
- number = "one";
- break;
- case '2':
- number = "two";
- break;
- case '3':
- number = "three";
- break;
- case '4':
- number = "four";
- break;
- case '5':
- number = "five";
- break;
- case '6':
- number = "six";
- break;
- case '7':
- number = "seven";
- break;
- case '8':
- number = "eight";
- break;
- case '9':
- number = "nine";
- break;
- }
- if (i <= length) {
- strOut += number;
- if (i < strInput.length()-1 && strInput.charAt(i+1) >= '0' && strInput.charAt(i+1) <= '9') {
- strOut += "-";
- }
- }
- }
- if (ch < '0' || ch > '9')
- strOut += ch;
- }
- System.out.println(strOut);
- strOut = "";
- }
- inputFile.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement