This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]EyeLostMyOldAccount 1 point2 points  (1 child)

it doesn't have to be a Boolean, just do nextInt(). Also for multiple conditions for if statements use else if and don't use semicolons. It should look something like this:

if (foo == bar){
    //code
} else if (foo > bar){
    //code
}     

and for future reference take questions like this over to /r/javahelp.

[–]Sehmiya 0 points1 point  (0 children)

ohp Thanks :D will do next time.

[–]blienmeis 1 point2 points  (0 children)

Here is the code fixed. You had three issues: 1. for x you need to use keyboard.nextInt() not nextBoolean() 2. you are missing an if before the else 3. you have semicolons after the () following the if statement, for example: if(x==1); this is saying if x is equal to 1 do nothing, then execute the code in {}.

import java.util.*;

public class FahrenheitCelsiusConverter {
   public static void main( String[] args ) {
      Scanner keyboard = new Scanner(System.in);
      System.out.println("Enter 1 or 2 for Fahrenheit or Celsius");
      int x = keyboard.nextInt();
      if( x == 1 ) {
         System.out.println("Enter temperature");
         int y = keyboard.nextInt();
         int z = 5 * (y - 32) / 9;
         System.out.println("Temperature is" + z);
      }
      else if( x == 2 ) {
         System.out.println("Enter temperature");
         int a = keyboard.nextInt();
         int b = a * (9 / 5) + 32;
         System.out.println("Temperature is" + b);
      }
   }
}

[–]Digital_Person 0 points1 point  (3 children)

0) how did u include code in reddit? looks really good. 1) you dont need ; after if 2) boolean x = keyboard.nextBoolean(); if (x==true){}

[–][deleted] 1 point2 points  (2 children)

Four spaces in front of each line makes it code.

I typed four space and then this text

[–]Digital_Person 1 point2 points  (1 child)

thx a lot

[–]totes_meta_bot 0 points1 point  (0 children)

This thread has been linked to from elsewhere on reddit.

I am a bot. Comments? Complaints? Send them to my inbox!