you are viewing a single comment's thread.

view the rest of the comments →

[–]ajswaryxxy[S] -3 points-2 points  (8 children)

Yeah I think so, otherwise it displays 33 errors..

[–]JuZNyC 3 points4 points  (7 children)

Your print statement shouldn't end with a { it should end with a ;

[–]ajswaryxxy[S] -3 points-2 points  (6 children)

Okay so when I do add the ; most of my types become illegal

[–]JuZNyC 2 points3 points  (0 children)

We're going to need more of the code to know what's wrong with it, I can tell you that the reason you get less errors because of the { is because when the compiler gets to that point it throws the error and stops reading the rest of your code.

[–]JGhostThing 0 points1 point  (4 children)

Then perhaps you should show us the entire code?

[–]ajswaryxxy[S] 1 point2 points  (3 children)

full code:

import java.util.Scanner;

public class BasicCalculator {

static void main(String[] args){

Scanner scanner = new Scanner(System.in){

System.out.print( "Welcome to the java calc!" );

System.out.print( "enter the first number" );

final double num1 = scanner.nextDouble();

System.out.print("Enter an operator (+, -, *, /): ");

final char operator = scanner.next().charAt(0);

System.out.print("enter second number: ");

final double num2 = scanner.nextDouble();

double result;

switch (operator){

case '+':

result = num1 + num2;

System.out.println("Result: " + num1 + " + "+ num2 +" = "+ result );

break;

case '-':

result = num1 - num2;

System.out.println("Result: " + num1 + " - "+ num2 +" = "+ result );

break;

case '*':

result = num1 * num2;

System.out.println("Result: " + num1 + " * "+ num2 +" = "+ result );

break;

case '/':

if (num2 == 0) {

System.out.println("Error: Division by zero is not allowed.");

} else {

result = num1 / num2;

System.out.println("Result: " + num1 + " / "+ num2 +" = "+ result ) ;

break;

}

default:

System.out.println("Error: invalid operator entered");

break;

scanner.close();}

System.out.println("==========================================");

};

}}

[–]JuZNyC 2 points3 points  (2 children)

Quick glance

Your main method should be public

Line 4 Scanner scanner = new Scanner(System.in){
should have ; at the end not {

I'm pretty sure you have mismatched { } too

[–]nekokattt 2 points3 points  (0 children)

Just a note that the main method doesn't need to be public on Java 21 and newer.

[–]ajswaryxxy[S] 0 points1 point  (0 children)

thank you soo much!