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 4 of 4

Thread: language Recognizer

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question language Recognizer

    Hi

    this is my project question in Data Structures



    and this is the code

    PHP Code:
    import java.util.Scanner;

    class 
    Stack {

        private 
    int top = -1;
        private 
    char stack[] = new char[10];

        public 
    void push(char a) {
            
    stack[++top] = a;
        }

        public 
    char pop() {
            return (
    charstack[top--];
        }

        public 
    void refill() {
            
    top stack.length 1;
        }

        public 
    void reset() {
            
    top = -1;
        }
    }

    public class 
    Class1 {

        public static 
    void main(String[] argsthrows Exception {
            
    Stack s1 = new Stack();
            
    Stack s2 = new Stack();
            
    Stack s3 = new Stack();

            
    boolean isPartOf false;

            
    Scanner input = new Scanner(System.in);
            
    int n0;
            
    char chch1ch2;

            
    System.out.println("========================================================================= ");
            
    System.out.println("Enter 10 letters for the language , , , WITHOUT SPACES BETWEEN THE LETTERS");

            for (
    int i 010i++) {
                
    ch = (charSystem.in.read();
                
    s1.push(ch);
            }

            
    System.out.println("========================================================================= ");
            
    System.out.println("The valid characters of your language are:");

            for (
    int i 010i++) {
                
    System.out.print(1);
                
    System.out.println(") ");
            }

            
    System.out.println("========================================================================= ");
            
    System.out.println("Enter the number of the letters of the word you want to check");

            
    input.nextInt();

            
    System.out.println("========================================================================= ");
            
    System.out.println("Enter the word you need to check");

            for (
    int i 0ni++) {
                
    ch = (charSystem.in.read();
                
                
    s2.push(ch);
                
            }
            for (
    int i 0ni++) {
                
    ch1 s2.pop();
                
    s1.refill();
                 
                for (
    int j 010j++) {
                    
    ch2 s1.pop();
                                if (
    ch1 == ch2) {
                        
    isPartOf true;
                        
    r++;
                        
    s3.push(ch2);
                        
    System.out.println("ch2 = " ch2);
                    } else if (
    isPartOf) {
                        
    isPartOf false;
                        break;
                    }
                }
            }
            if (
    isPartOf) {
                
    System.out.println("========================================================================= ");
                
    System.out.println("The word is part of the language\n");
            } else {
                
    System.out.println("========================================================================= ");
                
    System.out.println("The word is not a part of the langauge\n");
            }
        }

    it is working but not in all cases




    where is the wrong


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: language Recognizer

    it is working but not in all cases
    Add some comments to the program's output saying what is wrong with it and show what it should be.

    Please copy and paste here the contents of the command prompt window. Images do not allow copy or find of their contents.

    To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Dec 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: language Recognizer

    Please close this Thread

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: language Recognizer

    Please mark the thread as solved.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. which programming language can help me more
    By websit in forum Object Oriented Programming
    Replies: 1
    Last Post: June 24th, 2012, 09:14 PM
  2. Popular Language
    By Chillers in forum Java Theory & Questions
    Replies: 11
    Last Post: March 30th, 2012, 08:47 PM
  3. SMS SENDER RECOGNIZER
    By javalearn250 in forum Java Theory & Questions
    Replies: 1
    Last Post: October 4th, 2011, 06:25 AM
  4. Language translation
    By archanaanbu in forum Member Introductions
    Replies: 1
    Last Post: February 9th, 2011, 07:01 AM
  5. What does SCOPE actually mean in java language?
    By wAdeski in forum Java Theory & Questions
    Replies: 3
    Last Post: December 1st, 2010, 10:44 AM