Wonder Rabbit
Wonder Rabbit

Reputation: 21

Why does my code keep getting the error: <identifier> expected?

Okay so, I'm trying to do my programming homework and it's KILLING ME, because the online compilers I use keep giving me the same indentifier expected error, but I tried everything to fix it, and it never does! Please, please explain me what's wrong!

It gives me this exact error: /ListadeExercicio1.java:1: error: expected import:java.io.*;

Here's my code so far (it's in pt-br, please don't mind):


public class ListadeExercicio1 {
  public static void main (String args[]) {
    String s="";
    float num1=0;
    int numin1=0;
    int numin2=0;
    float cubo=0;
    float resto=0;
    float quadrado=0;
    float raizquadrada=0;
    float triplo=0;
    float acrescimo=0;
    float decrecimo=0;

    DataInputStream dado; 

  try {
    System.out.println("Insira o primeiro número para as operações:");
    dado=new DataInputStream(System.in); 
    s=dado.readLine(); 
    num1=Float.parseFloat(s); 

    System.out.println("Insira o segundo número para as operações:");
    dado=new DataInputStream(System.in);  
    s=dado.readLine(); 
    nota2=Integer.parseInt(s);

    System.out.println("Insira o terceiro número para as operações:");
    dado=new DataInputStream(System.in);  
    s=dado.readLine(); 
    nota2=Integer.parseInt(s);

//Cálculos

    cubo=num1*num1*num1;


    System.out.println("Media: " + media);
  } 
   catch (IOException erro) {
    System.out.println("Houve um erro na entrada de dados :(" +erro.toString());
  } 
}
}```

Upvotes: 2

Views: 1207

Answers (2)

Atakan Atamert
Atakan Atamert

Reputation: 235

You are probably missing import statements. Try adding these to your code,

import java.io.DataInputStream;
import java.io.IOException;
import java.lang.*; 

In addition to that, you also need to define variables media and nota2. You cannot initialize variable without defining it in Java.

Upvotes: 3

The problem is that you should've imported java.io.*; because you're using classes from that package and you didn't.

You should read about Java packages.

Also, I noticed that you tagged your question with both Java and JavaScript. Please note that, in spite of the names being similar, these are actually completely unrelated languages.

Upvotes: 1

Related Questions