File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes how totake user input for the string for this program ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how totake user input for the string for this program ?" Watch "how totake user input for the string for this program ?" New topic
Author

how totake user input for the string for this program ?

kishore srimat
Greenhorn

Joined: Dec 18, 2007
Posts: 5
import java.util.*;

public class StringReverseWord {

private static void doStringReverseWord() {

String a = " Rohit Khariwal Mohit Parnami";
Stack stack = new Stack();

// this statement will break the string into the words which are separated by space.
StringTokenizer tempStringTokenizer = new StringTokenizer(a);

// push all the words to the stack one by one
while (tempStringTokenizer.hasMoreTokens()) {
stack.push(tempStringTokenizer.nextElement());
}

System.out.println("\nOriginal string: " + a);

System.out.print("Reverse string: ");

// pop the words from the stack
while(!stack.empty()) {
System.out.print(stack.pop());
System.out.print(" ");
}

System.out.println("\n");
}


public static void main(String[] args) {
doStringReverseWord();
}

}

*********************************************
i want to do somethig like this template
*********************************************
public class Reverser {
public static String reverse(char[] original) {
// Implement this method.
}

public static void main(String[] args) {
System.out.println("Original: " + args[0]);
System.out.println("Reversed: " + reverse(args[0].toCharArray()));
}
}
Abhinav Srivastava
Ranch Hand

Joined: Nov 19, 2002
Posts: 349

You question is not clear. You are already getting the user input in
args[0], where is the problem?
kishore srimat
Greenhorn

Joined: Dec 18, 2007
Posts: 5
The program before the stars was my program and my prof gave this template and i wrote in normal static user input from the program not interatively at runtime when program starts i want to give the input and get the output and i am breaking my head i need to use args
Abhinav Srivastava
Ranch Hand

Joined: Nov 19, 2002
Posts: 349

Since this is an assignment, I would suggest that work your way out. You can look at System and InputStream api if you want interactive input.
[ January 14, 2008: Message edited by: Abhinav Srivastava ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Hint:
Your professor has already answered this for you.
Look at his code.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how totake user input for the string for this program ?