• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how totake user input for the string for this program ?

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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()));
}
}
 
Ranch Hand
Posts: 354
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hint:
Your professor has already answered this for you.
Look at his code.
 
reply
    Bookmark Topic Watch Topic
  • New Topic