The immediate issue is a missing open brace ({
) and an closing parenthesis ()
)
public static void main(String[] args) {
^--- This is important...
Scanner input = new Scanner( System.in);
^--- Also important :P
BufferReader br = new BufferReader(instream);
System.out.println("Enter your annual sales");
String annual = br.readLine();
int salary = 75_502_81;
int com = 38_28;
int compensation = annual * com + salary;
}
There’s no such class as BufferReader
, I think you mean BufferedReader
There’s no such variable instream
declared in you code, I think you might mean input
, but BufferedReader
won’t take input
as a valid input type, so I’m not sure what you intentions are here…
You’ll also be receiving warnings about an uncaught IOException
You can resolve these through the use of try-catch
I’m also curious about what 75_502_81
and 38_28
are suppose to mean? int
values can’t contain anything other then numeric values…
annual
is also String
, meaning you can’t perform any mathematical operations on it.
You will need to convert the value to an int
first…
public static void main(String[] args) {
Scanner input = new Scanner( System.in );
BufferedReader br = null;
try {
br = new BufferedReader(instream);
System.out.println("Enter your annual sales");
String annual = br.readLine();
int salary = 7550281;
int com = 3828;
int compensation = Integer.parseInt(annual) * com + salary;
} catch (IOException exp) {
exp.printStackTrace();
} finally {
try {
br.close();
} catch (Exception exp) {
}
}
}
But I’m left scratching my head as to why, when
public static void main(String[] args) {
Scanner input = new Scanner( System.in );
System.out.println("Enter your annual sales");
String annual = input.nextLine();
int salary = 7550281;
int com = 3828;
int compensation = Integer.parseInt(annual) * com + salary;
}
Will do the same thing…
7
solved Writing a java file [closed]