java help the matching parenthesis [java tokenize] [string input]

Q: I want some cash matching using a stack and do one another by the recursion. And the program will read any number string from standard input and output to standard out the results, good or bad, for each string. Someone recommended the java input stream to tokenize, but I have no idea how to do that. Im not really sure what or how I do this, other than when the program receives a , it will be some characters (in this case, parentheses matching, and the output of the good or bad.

– in principle: if there the right number of brackets (closed and open), and prints good if the string is corrent amount, and bad if too many open or closed or w / e. —

ex:
input: 977 503? ab (COB (fghijk) (lm nopq [r]) WXY STU) z? 977,503? ab (COB (fghijk) lm () nopqrstu wxyz? 977,503? ab (COB (fghijk) (no lm (PQ [r] STU) w) XY) z?

output:
Using stack:
good
bad
bad

Using recursion:
good
bad
bad

If someone can explain how to do this, many oblidged. I know very little Java, so Java does not help me much jargon


Best Answer: 1. Replace this:
String s = keyboard.next();
// Extract the digits from the code and store in the entered_digits array
for (int i=0; i<s.length(); i++)
{
entered_digits[i] = s.charAt(i) – '0'; // Convert char to corresponding digit
}

with:
// Extract the digits from the code and store in the entered_digits array
int Index = 0;
for (int i=0; i<actual_password.length; i++)
{
String s = keyboard.next();
entered_digits[Index++] = s.charAt(0) – '0'; // Convert char to corresponding digit
}

2. And replace:
if () // FILL IN HERE
{
System.out.println("Correct! You may now proceed.");
}
else
{
System.out.println("Error, invalid password entered.");
}

with:
if (isValid (actual_password, entered_digits, random_nums)) // FILL IN HERE
{
System.out.println("Correct! You may now proceed.");
}
else
{
System.out.println("Error, invalid password entered.");
}

3. This is the isValid method:
public static boolean isValid(int[] actual, int[] entered, int[] randnums)
{
int Index = 0;
boolean Valid = true;
while (Valid && (Index < actual.length))
{
int Code = actual[Index];
if (entered [Index] != randnums [Code])
{
Valid = false;
}
Index++;
}
return Valid;
}


BrainCode Java.
Re:LOL

As soon as I saw your original post I knew you had to go to Michigan Tech.

If you know very little Java, re-take Poplawski's class, you don't belong in Data Structures dude.


Think You Know Guitar Strings?
Re:You might be better off dropping the course and re-taking the earlier one (or doing some self-study) if you didn't learn its materials and aren't prepared.

Even if you get someone to write a working program for you, you'll fail the class tests and be even more unprepared for the next course you take.

You have to learn to think your way through problems on your own to be any good at programming, let alone software development.

It's not like algebra or calc 1 where you can mechanically solve problems by learning a simple formula or two.


The Ultimate Guide to Conder Tokens
Re:If you can't understand the examples that are written on your assignment's webpage, then it is useless for us to help you. You need to get a better understanding of not just Java but languages and algorithms in general.

You haven't even indicated that you have any original ideas or thoughts about the program. You have only regurgitated stuff from the assignment page. We are not going to write this assignment for you. You need to at least indicate that you have some damn clue what is going on.


CodeBrain.com.
Re:Everything you wanted to ever learn about java… (http://java.sun.com/j2se/1.4.2/docs/api/overview-summary.html)

String Theory: Guitar and Piano Chords in Parallel.
Re:yes, i read all that, but again, I know very little of java because of horrible teachings. So all the code there is usless to me. I don't know what it does. It's lacking exploritory comments. thats what i need help with. once I understand that, I can work on what I need to do to complete the assignment

thanks guys


Webmaster Video Course for Professionals
Re:I gave you a stack U& recursive algorithm…

where i put cin.get() use this equivolent java code…
InputStreamReader insr = new InputStreamReader(System.in);
BufferedReader inbr = new BufferedReader(insr);
StreamTokenizer input = new StreamTokenizer(inbr);

and look up the methods for using objects of class StreamTokenizer.

References for how to use the StreamTokenizer class are Objects have Class, chapter 13, and the java api for the StreamTokenizer class.

He even gives you an example program: SimpleReadQuotedWrite.java…

what more could you need than for someone else to write the entire program for you?


Best Engineering Resumes, Cover Letters and Career Advice
Re:http://www.csl.mtu.edu/cs2321/www/assignments/Program1ParenthesisMatch.htm

this is all I know about the program.

I know a few things about java, but last year's instructor who was supposed to build our java foundation of knowledge… well… sucked at teaching and I learned very little. One of those profs who you learn more form the lab coaches and upperclassmen than from him or his book (which was the course book as well…. eugh!) HOWEVER! You don't get in trouble for using things you don't know already. I really don't need to stick to the assignment specifics, only the recursion and stack part. the parts that make each work are OYO (on your own).


Freedom Lifestyle Income Program
Re:What parts of the language has your instructor gone over so far? You could get in trouble using parts of the language you "aren't supposed to know" yet.

Did the assignment include any suggestions, hints, an outline of the expected approaches?


Get 75%! ::: $31.85 Front & $45.73 Back! ::: Top Secret Magic Code
Re:then convert my algorithms to java.
algoithms work whether you use java, C++, vb… whatever…
you just have to figure out the correct coding language.

cuz i dont know the java equivolent of cin.get() which is the C++ tokenizer.


Double Your Cup Size, Natural Breast Enlargment
Re:only can do in java, sorry. thats why the title says "java help needed…"

Re:C++. use cin.get()… it retrieves 1 character. Use 3 char stacks.
Left pars on one stack… Right Pars on another. Everything else on third.
Push them. Pop them. Compare. Done.

———————————-

Java sux as a whole. C++ is more versatile and offers much better performance. who wants a language which has to be interpereted and run inside a java virtual processor, when you can have one which is compiled directly into binary and runs on its own.

About the recursion…

process (string)
{
handle first character using cin.get().
(Left_par++ or Right_par++)

if string not empty…process(string minus first character)
else
compare (Left_par, Right_par)
}

edit: dammit I posted in a dead thread. too lazy to copy it to other thread.


Related posts

Leave a comment

0 Comments.

Leave a Reply


click to changeSecurity Code

[ Ctrl + Enter ]