473,396 Members | 2,108 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

help on strings

hello everyone could teach me how to make the user input instead of me
here my code i just needed my teststack to let the user input instead of me could tell me what to do ?

Expand|Select|Wrap|Line Numbers
  1. class Stack {
  2.   private int maxSize;
  3.  
  4.   private char[] stackArray;
  5.  
  6.   private int top;
  7.  
  8.   public Stack(int s) {
  9.     maxSize = s;
  10.     stackArray = new char[maxSize];
  11.     top = -1; 
  12.   }
  13.  
  14.   public void push(char j) {
  15.     stackArray[++top] = j;
  16.   }
  17.  
  18.   public char pop() {
  19.     return stackArray[top--];
  20.   }
  21.  
  22.   public char peek() {
  23.     return stackArray[top];
  24.   }
  25.  
  26.   public boolean isEmpty() {
  27.     return (top == -1);
  28.   }
  29.  
  30.   public boolean isFull() {
  31.     return (top == maxSize - 1);
  32.   }
  33. }
Expand|Select|Wrap|Line Numbers
  1. import java.util.Scanner;
  2.  
  3.  
  4. public class TestStack {
  5. public static void main(String[] args) {
  6. String STS = " STS";
  7. int stackSize = STS.length();
  8.  
  9. Stack theStack = new Stack(stackSize);
  10.  
  11.  
  12. for (int j = 0; j < STI.length(); j++) {
  13. char ch = STS.charAt(j);
  14. theStack.push(ch);
  15. }
  16.  
  17. while (!theStack.isEmpty()) {
  18. char ch = theStack.pop();
  19. System.out.println(ch);
  20. }
  21. }
  22. }
Jan 11 '10 #1
4 1824
pbrockway2
151 Expert 100+
Use the Scanner (which you've imported...) to get the user's input.

Have a read of the API documentation to find useful methods for obtaining a string from the user.
Jan 11 '10 #2
i mean where do i put the inputs im really lose when it comes to let the user input im always fixed i dont let the user input but you point me to the right direction where to put this input string code in my stack/string code and which line should i start with when it comes to this input stuff im super lose and my code all about reversing word output like this

before: STI
after:ITS

my code works but my professor wants me to let the user input he such a pain in the ass to me but i have to do it my problem is i really don't know where to start input and which line should it be could please point me to the right direction please
Jan 11 '10 #3
pbrockway2
151 Expert 100+
You can identify in your existing code where (the only time) the string is assigned to. And you have the API docs that describe how to get user input.

I can't see what else I can do short of writing teh codes. And I'm not going to do that (principally because I don't see that as helping.) Consult your textbook and make an attempt! In all sincerity, if you can't take the next step forward you really should talk to your teacher.
Jan 11 '10 #4
thanks alot man now my only problem is how to display after the reversal could give me a little tip on how to do it please here my code please where do i put the after the reversal code please i really need help here just a little im still new it i already broke my brain think this please where do i put the after reverse code

Expand|Select|Wrap|Line Numbers
  1. import java.util.Scanner;
  2.  
  3. public class TestStack {
  4.   public static void main(String[] args) {
  5.     Scanner scan = new Scanner(System.in);
  6.     String name =null;
  7.     System.out.println("Input your name: ");
  8.     name = scan.nextLine();
  9.     System.out.println(" before: " + name);
  10.     int stackSize = name.length();
  11.  
  12.     Stack theStack = new Stack(stackSize);
  13.  
  14.     for (int j = 0; j < name.length(); j++) {
  15.       char ch = name.charAt(j);
  16.       theStack.push(ch);
  17.     }
  18.  
  19.     while (!theStack.isEmpty()) {
  20.       char ch = theStack.pop();
  21.       System.out.println(ch);
  22.     }
  23.   }
  24. }
Jan 11 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Jack Smith | last post by:
Can some one help me with this proof? Let L be the language of strings over {a,b} recursively defined by the following set of rules (i) the string ^ is in L (^ is the null string). (ii) for...
5
by: ArShAm | last post by:
Hi there Please help me to optimize this code for speed I added /O2 to compiler settings I added /Oe to compiler settings for accepting register type request , but it seems that is not allowed...
3
by: Mahmood Ahmad | last post by:
Hello, I have written a program that reads three types of records, validates them acording to certain requirements and writes the valid records into a binary file. The invalid records are...
0
by: Jon | last post by:
We have a asp.net app that runs like the following in a single-site scenario. Directory structure: c:\inetpub\wwwroot\myapp - aspx files, global.asax and web.config c:\inetpub\wwwroot\myapp\bin...
9
by: Diane | last post by:
Could you please explain me how can I output nested strings? Here is an example: "adsd{rfkm}xcv" The output should start from the inner parentheses, such as: dfF rfkm
4
by: WaterWalk | last post by:
Hello, I'm currently learning string manipulation. I'm curious about what is the favored way for string manipulation in C, expecially when strings contain non-ASCII characters. For example, if...
4
by: Robin Haswell | last post by:
Okay I'm getting really frustrated with Python's Unicode handling, I'm trying everything I can think of an I can't escape Unicode(En|De)codeError no matter what I try. Could someone explain to...
2
by: almurph | last post by:
Hi, Hope you can help me. This is a trick one - at least I think so. I have 2 strings. I have to calculate the "score" of the strings. Score is determined by matching patterns of letters within...
4
by: Debbiedo | last post by:
My software program outputs an XML Driving Directions file that I need to input into an Access table (although if need be I can import a dbf or xls) so that I can relate one of the fields...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.