Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

8
[Java] Having trouble understand what I'm doing wrong.
Author Summary
Advisery is in Java
Post Body

Hello. Here is my code:

import java.util.Scanner;

public class SpaceBoxer{
  public static double planets(int world){
    double planetmulti;

    if (world == 1){
      planetmulti = 0.78;
    }
    else if (world == 2){
      planetmulti = 0.39;
    }
    else if (world == 3){
      planetmulti = 2.65;
    }
    else if (world == 4){
      planetmulti = 1.17;
    }
    else if (world == 5){
      planetmulti = 1.05;
    }
    else if (world == 6){
      planetmulti = 1.23;
    }
    return planetmulti;
  }
  public static void main(String[] args){
    Scanner keyboard = new Scanner(System.in);

    int weight, theplanet;
    System.out.print("What is your weight?");
    weight = keyboard.nextInt();

    System.out.println("Okay, now what planet are you visiting?");
    System.out.println("   1. Venus   2. Mars    3. Jupiter");
    System.out.println("   4. Saturn  5. Uranus  6. Neptune");
    theplanet = keyboard.nextInt();

    System.out.println("Okay, so your weight would on "   weight * planets(theplanet));
  }
}

When I try to compile, however, I get this error:

SpaceBoxer.java:25: error: variable planetmulti might not have been initialized. 

return planetmulti;
       ^

Any help? Is it due to me declaring it a double instead of something else? I'm not sure what I'm doing wrong here.

Author
Account Strength
100%
Account Age
12 years
Verified Email
Yes
Verified Flair
No
Total Karma
24,702
Link Karma
6,007
Comment Karma
18,662
Profile updated: 6 days ago
Posts updated: 9 months ago

Subreddit

Post Details

Location
We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
11 years ago