//This program will prompt for user to enter in the Fahrenheit temperature and convert it to Celsius.

import java.util.Scanner;
public class Project4 
    {
    public static void main (String[]args)
        {
        double temperature;
        double celsius;
        Scanner scan = new Scanner (System.in);

        System.out.println("Enter the current temperature in Fahrenheit: ");
        temperature = scan.nextDouble();

        celsius = ((temperature-32)*5/9);       
        }
    System.out.println("So the temperature in Celsius is " + celsius);
    }

The final println command has a syntax error with "println". Why is that?

Recommended Answers

All 7 Replies

Because it is outside the main function :P

You have to move the

System.out.println("So the temperature in Celsius is " + celsius);

line into the main method. At the moment it is placed outside the main method

Put the closing curly brace in line 14 just after the System.out.println line which gives the error.

Thanks!

I realized that and moved it within the main function and then I was on my way to delete this thread. But hey, I'll leave it up as a thanks and help for others.

//Have the to floating numbers add together, divided, and multiplied.
public class Project3 
    {
    public static void main (System[]args)
        {
        float a,b;

        a=(float) 1.23;
        b=(float) 2.34;

        System.out.println("The sum of the two numbers is "[COLOR="Red"] a[/COLOR]+b);
        }
    }

I don't know why this one won't compile! It's within the main function. O.o

In java we use '+' for String concatenation. So in the System.out.println method you are trying to concatenate without using '+'.

Try this

System.out.println("The sum of the two numbers is "+ (a+b));

Also try to understand the difference between above line and the following line

System.out.println("The sum of the two numbers is "+ a+b);

ugh. Amateur mistake. I'll be more careful for little things like that. Thanks again. I'm sure I'll be back. I'm driven to fully understand programming.

Try to understand the compilation error message given by the compiler :) :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.