# Error in java statment

Page 1 of 1

## 6 Replies - 2241 Views - Last Post: 21 November 2012 - 06:27 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=301061&amp;s=65638deabe95b8d79c21c095082ef838&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Asma-j

Reputation: 0
• Posts: 3
• Joined: 21-November 12

# Error in java statment

Posted 21 November 2012 - 03:16 AM

I was try to solve this "Write a program that allows the user to convert a temperature given in degrees from either Celsius to Fahrenheit or Fahrenheit to Celsius. Use the following formulas:
Degrees_C = 5(Degrees_F -32)/9
Degrees_F = (9(Degrees_C)/5) + 32)
Prompt the user to enter a temperature and either a C or c for Celsius is entered, or to Celsius if Fahrenheit is entered. Display the result in a readable format. If anything other than C, c, F or f is entered, print an error message and stop."

when i test it i have errors
```import java.util.Scanner;

/**

Convert a temperature in degrees from either celsius to

fahrenheit or fahrenheit to celsius.

*/

public class TempConvert

{

public static void main(String[] args)

{

//Have the user to enter a temperture in celsius or fahrenheit

System.out.println("Enter a temperture");

System.out.println("In C or c for celsius");

System.out.println("And F or f for fahrenheit");

double degrees_F;

double degrees_C;

degrees_F = keyboard.nextDouble;

degrees_C = keyboard.nextDouble;

//Convert each temperture from celsius to fahrenheit and fahrenheit to celsius.

if (degrees_C){

celsius = (5*(10 - 32)/9);

System.out.println("Your degrees will be in fahrenheit");

}

else if (degrees_F){

fahrenheit = (9*(10/5)) + 32);

System.out.println("Your degrees will be in celsius");

}

else{

System.out.println("Try again");

//Convert the temperature to fahrenheit if celsius is enter
//or to celsius if fahrenheit is entered.

System.out.println("The temperture is " + degrees);

}

}

}

```

This post has been edited by pbl: 21 November 2012 - 06:20 AM
Reason for edit:: Fixed code tags

Is This A Good Question/Topic? 0

## Replies To: Error in java statment

### #2 binarymatter

Reputation: 0
• Posts: 13
• Joined: 18-September 12

## Re: Error in java statment

Posted 21 November 2012 - 03:21 AM

What error are you getting?

### #3 binarymatter

Reputation: 0
• Posts: 13
• Joined: 18-September 12

## Re: Error in java statment

Posted 21 November 2012 - 03:28 AM

if (degrees_C){ a if statement should hold a true or false value as degrees_C is a double value is should be compare to something to make it a true or false statement example degrees_C == 10.5

### #4 Asma-j

Reputation: 0
• Posts: 3
• Joined: 21-November 12

## Re: Error in java statment

Posted 21 November 2012 - 03:51 AM

binarymatter, on 21 November 2012 - 03:28 AM, said:

if (degrees_C){ a if statement should hold a true or false value as degrees_C is a double value is should be compare to something to make it a true or false statement example degrees_C == 10.5

3 lines show this :
not resolved

and this:
syntax error on token " else " , delete this token ..

Asma-j, on 21 November 2012 - 03:50 AM, said:

binarymatter, on 21 November 2012 - 03:28 AM, said:

if (degrees_C){ a if statement should hold a true or false value as degrees_C is a double value is should be compare to something to make it a true or false statement example degrees_C == 10.5

errors
3 lines show this :
not resolved

and this:
syntax error on token " else " , delete this token ..

### #5 raghav.naganathan

• Perfectly Squared ;)

Reputation: 410
• Posts: 1,449
• Joined: 14-September 12

## Re: Error in java statment

Posted 21 November 2012 - 03:53 AM

Please post the exact errors you are getting. That will probably help us understand where exactly in your code the problem is occurring.

One thing you need to note here is

if(anything) will always give TRUE, unless that anything is 0

Also, you need to declare the variables celsius and fahrenheit before you can use them in your if and elseif conditions.

regards,
Raghav

This post has been edited by raghav.naganathan: 21 November 2012 - 04:00 AM

### #6 Asma-j

Reputation: 0
• Posts: 3
• Joined: 21-November 12

## Re: Error in java statment

Posted 21 November 2012 - 05:51 AM

in attachment showing an errors

### #7 pbl

• There is nothing you can't do with a JTable

Reputation: 8379
• Posts: 31,956
• Joined: 06-March 08

## Re: Error in java statment

Posted 21 November 2012 - 06:27 AM

indent it correctly asnd it will become obvious
(in Eclipse: <CTRL>A <CTRL>I)

as far as the second error is concerned, float constant in Java are double so
5.0 / 9.0 is a double constant
5.0f / 9.0f is a float constant

your variables are declared float not double so if you mixed them, the compiler signals a possible loss of precision

This post has been edited by pbl: 21 November 2012 - 06:30 AM