java - print numbers as word equivalent but in reverse

Discussion in 'Programming' started by javanewbie, Sep 8, 2011.

  1. javanewbie

    javanewbie New Member

    Joined:
    Sep 8, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    I am working on a program in java on notepad++ that opens a file(reverse.in) opens it and extracts the integers to an array. Now I need convert the numbers to words and print them out in reverse. For example 0 1 2 3 would become three two one zero.

    I have the array set but have no idea how to convert the numbers and print in reverse. This is only my 3rd week of java so the more info the better!!!
    Code:
     
    import java.util.*;
    import java.io.*;
     
    public class Reverse1{
    public static void main(String[] args) throws Exception{
    int i =0;
    File file = null;
     file = new File("Reverse.in");
     BufferedReader bufRdr  = new BufferedReader(new FileReader(file));
     String line = "";
     String [] numbers = new String[10];
     
      while ((line = bufRdr.readLine()) != null){
    
      StringTokenizer st = new StringTokenizer(line,",");
    while (st.hasMoreTokens()) {
    numbers[i]= st.nextToken();
     } 
    i++;
    }
    
    for (i = 1; i < numbers.length; i++) {  
    System.out.print("" + numbers[i]); 
    System.out.println();
    }  
    System.out.println();
    }
    }
     
    Last edited by a moderator: Sep 9, 2011

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice