• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

problems with my first java programming assignment

skim milk

Diamond Member
We only learned just the basics so I want to keep it as simple as possible

Here's the code I wrote so far:

"public class Degrees
{
public static void main (String [] args)
{
int DegreesC, DegreesF;

Scanner keyboard = new Scanner (System.in);
System.out.println("Enter a temperature in degrees Fahrenheit:");
DegreesF = keyboard.nextInt( );

DegreesC = 5 * (DegreesF - 32)/9;

System.out.println(DegreesF + "degrees Fahrenheit =");
System.out.println(DegreesC +"degrees Celsius.");

}
}
"
I'm getting errors when I try to compile

thanks
 
it says cannot find symbol
symbol: class Scanner
location class Degrees
Scanner keyboard = new Scanner <System.in>;

2 errors
 
Originally posted by: tfinch2
Because your not including the Scanner package into your class.

import java.util.Scanner;

I assume?

thanks that fixes the compiling problem


However, I'm wondering how I can get this output?

Enter a temperature in degrees Fahrenheit: 72
72 degrees Fahrenheit = 22.2 degrees Celsius.

Mine looks like this:
Enter a temperature in degrees Fahrenheit:
72
72 degrees Fahrenheit =
22 degrees Celsius.

How do I get 22.2 with the decimal point?
and why is my format so off? I don't know how to get the 72 degrees F = 22 degrees C on the same line

 
Also, when you use System.out.println(), it puts a newline at the end of the string. If you instead used System.out.print() for the first statement, and then System.out.println() for the second, you'd end up with the formatting you're looking for (in terms of lines). An alternative would be to put both into one println() statement - System.out.println(DegreesF + "degrees Fahrenheit =" + DegreesC + "degrees Celsius");
 
Back
Top