Error class expected!

Asked

Viewed 464 times

1

With this code I get the error:

error: class expected

import javax.swing.JOptionPane;  

public class MenorIdade {  
    public static void main(String[] args) {  
        String[] nomes = new String[5];  
        int [] idades = new int[5];  
        int maisJovem = 0;  

        for (int i = 0; i <= 4; i++) {  
            nomes[i] = JOptionPane.showInputDialog("Informe o nome");  
            idades[i] = int.parseInt(JOptionByte.showInputDialog("Informe a idade"));

            if (idades[i] < idades[maisJovem]) {  
                maisJovem = i;  
            }
        }  

        JOptionPane.showMessageDialog(null, nomes[maisJovem] + " é mais jovem e tem " + idades[maisJovem] + " anos.");  

    }  
}  

2 answers

1


Code modifications:

public static void main(String[] args) 
{
    String[] nomes = new String[5];  
    int [] idades = new int[5];  
    int maisJovem = 0;  
    String showInputDialog = "";
    for (int i = 0; i <= 4; i++) {  
        nomes[i] = JOptionPane.showInputDialog("Informe o nome");  
        showInputDialog = JOptionPane.showInputDialog("Informe a idade");
        idades[i] = Integer.parseInt(showInputDialog);
        if (idades[i] < idades[maisJovem]) {  
            maisJovem = i;  
        }
    }  
    JOptionPane.showMessageDialog(null, nomes[maisJovem] + " é mais jovem e tem " + idades[maisJovem] + " anos.");          
}
  • It would be a valid way, @Maria. At first I didn’t understand why the String showInputDialog; intermediate, but I ended up seeing. But, even functional, is not necessary, since it can do the parse directly.

  • I’ll edit my answer so Camuratti can look at the two forms, okay?

  • @Gustavocinque, quiet do yes...!

  • @Gustavocinque in relation to parse, in my opinion this code needs to be improved, because there is no criticism in the contents that can be typed...

  • Um, it’s just that I’ve always used the parse on input, hehe. Speed on writing and reading, for me.

  • So at this point I disagree and if the guy type letter instead of number? not even a block try catch he put understand

  • 1

    You’re right. If it did, it would make a beautiful NumberFormat.

  • 1

    Thanks for the help, @Maria!!

Show 3 more comments

0

On line 11:

idades[i] = int.parseInt(JOptionByte.showInputDialog("Informe a idade"));

You cannot use the primitive type of a class to make method calls, so the correct one would be Integer.parseInt();. I don’t know if it would be just me, but my IDE(Eclipse) didn’t recognize the class JOptionByte.

One way would be to replace the part JOptionByte and use the JOptionPane even, getting like this:

idades[i] = Integer.parseInt(JOptionPane.showInputDialog("Informe a idade"));

  • My Netbeans doesn’t recognize it either. @Gustavocinque

  • Thanks for the help @Gustavocinque

  • @Camuratti, if you found any of the answers useful, validate them as the best, so you would close the question ;)

Browser other questions tagged

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