I am currently in a intro java programming course at my college. My code works fine I am just trying to add a loop that will ask the user (y or n) if they would like to input another weight. The professor had posted a yesorno java program example although it is not available and still have not heard back. I emailed the lab professor who had said to add a while loop with
although i could not get that to work either or maybe I am doing it wrong. This is what I currently have... thanks.
while( condition ) {
//do input and output of weights
//ask if they want to go again
}
although i could not get that to work either or maybe I am doing it wrong. This is what I currently have... thanks.
import java.util.*;
//I have set Planets as my main class
public class Planets
{
public static void main(String[] args)
{
//I have declared the following variables that will be used in my program
//I used double since decimals will be used in weights.
double weight;
double mercury;
double venus;
double jupiter;
double saturn;
//I have created a Scanner object and connected it to the system in object
Scanner scan = new Scanner(System.in);
//I have prompted the user to input a value for the weight variable
System.out.println("Please enter your Earth weight in pounds.");
weight = scan.nextDouble();
//I have included the calculations used to determine weights on other planets
mercury = 0.4 * weight;
venus = 0.9 * weight;
jupiter = 2.5 * weight;
saturn = 1.1 * weight;
//This line will display the weights.
System.out.print("Your weight on the following planets are: " + "\nMercury =" + mercury + "\nVenus = " + venus + "\nJupiter = " + jupiter + "\nSaturn =" + saturn);
//This will ask the user if they would like to enter another weight
{String cont= "Y";
while(cont.equals("Y"));
System.out.println("Do you want to continue Y/N ?");
cont=scan.nextLine();
}
}
}