Build error

Asked

Viewed 58 times

0

Guys, I’m making two mistakes and I don’t know how to fix it.

Follow the code below:

import java.io.*;
import java.util.*;

public class Pilha{

int elementos[];
int topo;

public Pilha(){
    elementos = new int[10000000];
    topo = -1;
}

public boolean empty(){
    return (topo == -1);
}

public int size (){
    return topo+1;
}

public int top(){
    return elementos[topo];
}

public int pop(){
    int e;
    e = elementos[topo];
    topo--;
    return e;
}

public void push(int e){
    topo++;
    elementos[topo] = e;
}

public static void main(String args[]) {
    Scanner in = new Scanner(System.in);
    String entrada = in.next();

    Pilha stack = new Pilha ();
    int var = entrada.length();

    int i = 0;

    while(i < var){
        if(!stack.empty() && stack.top() == '(' && entrada.charAt(i) == ')' ){
            stack.pop();
        }else stack.push(entrada.charAt(i));
        i++;
    }

    System.out.println(entrada.size() - stack.size());
}
}
 **2 errors
 lista1.java:4: error: class Pilha is public, should be declared in a file named Pilha.java
 public class Pilha{
        ^
 lista1.java:54: error: cannot find symbol
         System.out.println(entrada.size() - stack.size());
                                   ^
   symbol:   method size()
   location: variable entrada of type String**

PROBLEM LINK: here

1 answer

3


lista1.java:4: error: class Stack is public, should be declared in a file named Stack.java

The Stack class is public, and must be declared in a file called Stack.java. 1

lista1.java:54: error: cannot find Symbol System.out.println(input.size() - stack.size());

Symbol: method size()

Location: variable entry of type String

The variable entrada, of the kind String, does not have the method size(). 2

Therefore, to resolve these build issues, you should change the file name as requested, and use the length method for the size of String.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.