Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how totake user input for the string for this program ?

 
kishore srimat
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 354
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You question is not clear. You are already getting the user input in
args[0], where is the problem?
 
kishore srimat
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 354
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hint:
Your professor has already answered this for you.
Look at his code.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic