Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

error: '{' expected

0 votes
asked Sep 13, 2020 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

+1 vote
answered Sep 14, 2020 by Peter Minarik (84,720 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, 2020 by Nitishkumar (100 points)
I didn't find  save file  in online gdb
commented Sep 24, 2020 by Peter Minarik (84,720 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 Sep 28, 2020 by Jayden Neifert Reeves (530 points)
First, start by putting Main instead of that other class, then try beautify, it adds }'s where you need them.
0 votes
answered Sep 28, 2020 by Jayden Neifert Reeves (530 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.
...