Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Please help me on this delimeter check program please...

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Please help me on this delimeter check program please...

    java program that checks the pairing of (); []; {} ... i mean, for example, the equations inputed is a = {x[3*2(1+9)]+99}.. we know that there is no error in that eq... then the result would be *empty* which means there is no error.... but if you input a = {x[3*2(1+9]) + 99} , then there is an error... .the output would be ERROR.... because ] AND ) are swapped... please help me o.O


  2. #2
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default Re: Please help me on this delimeter check program please...

    Do you honestly think that you constructed a valid question, which is clear and understandable?

    Re-word everything, ask a direct question, specify your problems along with any exception messages and post some code which you've started writing (must be relevant!).
    But note, this is not a homework service and no one is going to hand you the code on a silver platter.

    Oh, and in the members intro section? really?
    Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code

  3. The Following User Says Thank You to newbie For This Useful Post:

    KathCasison (March 10th, 2012)

  4. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,337
    Thanks
    182
    Thanked 830 Times in 773 Posts
    Blog Entries
    5

    Default Re: Please help me on this delimeter check program please...

    Thread moved. KathCasison, please read the forum rules, and I would highly recommend reading the getting help link in my signature.

  5. #4
    Junior Member
    Join Date
    Mar 2012
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Please help me on this delimeter check program please...

    Sorry.... I would like to ask some help for my homework. I requires a program that checks delimeters.. I've started the codes but it doesn't work properly.. here it is:




    import java.util.*;

    public class thom{
    public static void main (String args[]){

    Stack st=new Stack();
    Scanner thom=new Scanner(System.in);

    LinkedList<Character>list;
    list=new LinkedList<Character>();

    String state=" ";
    System.out.print("Input statement: ");
    state=thom.nextLine();
    int b=0;

    for(int a=0;a<state.length();a++){

    if ((state.charAt(a) == '/')&&(state.charAt(a+1) == '*')){
    st.push(new Character(state.charAt(a)));
    list.add(new Character(state.charAt(a)));
    st.push(new Character(state.charAt(a+1)));
    list.add(new Character(state.charAt(a+1)));
    }

    if ((state.charAt(a) == '*')&&(state.charAt(a+1) == '/')){

    b=list.getLast();
    if (b=='*'){
    st.pop();st.pop();}

    else
    st.push(new Character(state.charAt(a+1)));
    list.add(new Character(state.charAt(a+1)));
    st.push(new Character(state.charAt(a)));
    list.add(new Character(state.charAt(a)));
    }

    if (state.charAt(a) == '['){
    st.push(new Character(state.charAt(a)));
    list.add(new Character(state.charAt(a)));
    }

    if (state.charAt(a) == ']'){

    b=list.getLast();
    if (b=='['){
    st.pop();}

    else
    st.push(new Character(state.charAt(a)));
    list.add(new Character(state.charAt(a)));

    }

    if (state.charAt(a) == '('){
    st.push(new Character(state.charAt(a)));
    list.add(new Character(state.charAt(a)));
    }

    if (state.charAt(a) == ')'){

    b=list.getLast();
    if (b=='('){
    st.pop();
    }
    else
    st.push(new Character(state.charAt(a)));
    list.add(new Character(state.charAt(a)));
    }

    if (state.charAt(a) == '{'){
    st.push(new Character(state.charAt(a)));
    list.add(new Character(state.charAt(a)));
    }

    if (state.charAt(a) == '}'){


    b=list.getLast();
    if (b=='{'){
    st.pop();
    }
    else
    st.push(new Character(state.charAt(a)));
    list.add(new Character(state.charAt(a)));
    }

    }

    try{
    System.out.println(" "+st);
    }catch(EmptyStackException e){
    System.out.println("empty stack");
    }

    if(st.isEmpty()){
    System.out.print(" No error");
    }
    else
    System.out.print(" error");




    }
    }

  6. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,130
    Thanks
    52
    Thanked 2,286 Times in 2,257 Posts

    Default Re: Please help me on this delimeter check program please...

    Please edit your post and remove the coloring. It is almost unreadable.

    Also wrap your code in code tags: http://www.javaprogrammingforums.com...do=bbcode#code

Similar Threads

  1. java program check for files
    By Creeper in forum Java Theory & Questions
    Replies: 2
    Last Post: February 29th, 2012, 01:38 PM
  2. Check Password Program
    By m2msucks in forum What's Wrong With My Code?
    Replies: 8
    Last Post: December 6th, 2011, 12:39 AM
  3. Java Program to Check whether a Expression is Valid using Stack
    By rainbow9 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 12th, 2011, 01:11 AM
  4. how to check the value
    By javaking in forum Java Servlet
    Replies: 2
    Last Post: July 22nd, 2010, 06:56 AM
  5. Problem in AWT and IFrame implementaion
    By AZBOY2000 in forum What's Wrong With My Code?
    Replies: 9
    Last Post: April 24th, 2009, 03:41 AM