error: '{' expected

+1 vote
asked Sep 13 by Neph Warner (130 points)
What do I have to do to fix this error?

java

import java.util.Scanner;

public class Arithmetic_Expressions.java {

    public static void main(String[] args)   
    
    {
      
      Scanner scnr = new Scanner(System.in);
      
      double firstDouble;
      double secondDouble;
      double thirdDouble;
      
      System.out.println("Enter firstDouble: ");
      firstDouble = scnr.nextDouble();
      
      System.out.println("Enter secondDouble: ");
      secondDouble = scnr.nextDouble();
      
      System.out.println("Enter thirdDouble: ");
      thirdDouble = scnr.nextDouble();
      
      double resultOne = (thirdDouble + secondDouble)/firstDouble;
      double resultTwo = (thirdDouble * secondDouble)/(firstDouble + secondDouble);
      
      System.out.println("First Result " + resultOne);
      System.out.println("Second Result " + resultTwo);
      
   }
   
}

3 Answers

0 votes
answered Sep 14 by Peter Minarik (7,820 points)
In Java, every class has to go to its own file.

So either move your code to a file called Arithmetic_Expressions.java (the default file name is Main.java) -- you can create a new file with the first icon left to the RUN button --, or rename your class to Main from Arithmetic_Expressions.

Also, Arithmetic_Expression.java is an invalid class name as it contains a dot.
commented Sep 19 by Nitishkumar (100 points)
I didn't find  save file  in online gdb
commented 5 days ago by Peter Minarik (7,820 points)
You cannot rename the Main.java.

If you create a new file, you can move the mouse over the tab with the name of the file. It has three dots and you can rename files there.
0 votes
answered 22 hours ago by Jayden Neifert Reeves (510 points)
First, start by putting Main instead of that other class, then try beautify, it adds }'s where you need them.
0 votes
answered 22 hours ago by Jayden Neifert Reeves (510 points)
here is the working program for java

import java.util.Scanner;
  
  public class Main
  {
  public static void main (String[]args)
  {

    Scanner scnr = new Scanner (System.in);

    double firstDouble;
    double secondDouble;
    double thirdDouble;

    System.out.println (" Enter firstDouble: ");
    firstDouble = scnr.nextDouble ();

    System.out.println (" Enter secondDouble: ");
    secondDouble = scnr.nextDouble ();

    System.out.println (" Enter thirdDouble: ");
    thirdDouble = scnr.nextDouble ();

    double resultOne = (thirdDouble + secondDouble) / firstDouble;
    double resultTwo =
      (thirdDouble * secondDouble) / (firstDouble + secondDouble);

    System.out.println ("First Result " + resultOne);
    System.out.println ("Second Result " + resultTwo);

  }

}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...