Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Java 

Repeat first while loop if condition in second while loop is true

Hey guys. Trying to figure out how to get the first while loop to repeat if the if statement inside the second while loop is true.

Code
import java.util.Scanner;
import java.text.*;

public class TemperatureConversion
{
    public static void main(String[] args)
    {
        System.out.println("Welcome to the Temperature Converter\n");
        Scanner scChoice = new Scanner(System.in);
        Scanner scTemp = new Scanner(System.in);
        Scanner scCont = new Scanner(System.in);
        String choice;
        String cont;
        double finalTemp;
        double fahrenheit;
        double celsius;
        boolean loop = true;
        boolean contAsk = false;
        DecimalFormat df = new DecimalFormat("###,###.##");
        
        System.out.print("Would you like to convert Fahrenheit or Celsius? (F/C):");
        choice = scChoice.next();

        while(loop = true){
                        
            if(choice.equalsIgnoreCase("f")){
                System.out.print("Enter the temperature:");
                fahrenheit = scTemp.nextDouble();
                finalTemp = (fahrenheit - 32) * .5556;
                System.out.print(fahrenheit + " degrees Fahrenheit is " + df.format(finalTemp) + " degrees Celsius.\n");
                contAsk = true;
                loop = false;
                break;
            }else if (choice.equalsIgnoreCase("c")){
                System.out.print("Enter the temperature:");
                celsius = scTemp.nextDouble();
                finalTemp = 32 + (celsius * 1.8);
                System.out.print(celsius + " Celsius is " + df.format(finalTemp) + " degrees Fahrenheit.\n");
                contAsk = true;
                loop = false;
                break;
            }else if (!choice.equalsIgnoreCase("f") && !choice.equalsIgnoreCase("c")){
                System.out.print("Error: invalid entry\n");
                System.out.print("Would you like to convert Fahrenheit or Celsius? (F/C):");
                choice = scChoice.next();
                }
            }
        
            System.out.println("Continue? (Y/N):");
            cont = scCont.next();
        
        while(contAsk = true){
                
            if(cont.equalsIgnoreCase("y"))
            {
                loop = true;
            }else if (!cont.equalsIgnoreCase("y") && !cont.equalsIgnoreCase("n")){
                System.out.println("Error: invalid entry\n");
                System.out.println("Continue? (Y/N):");
                cont = scCont.next();  
            }else if (cont.equalsIgnoreCase("n"))
                return;
            }
        }
}


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C] by blackcoder00Mar 17, 2021 01:15 PM 4 159 Mar 17, 2021 01:15 PM
Last Post: Loki123
[Shell] by friiz1337Oct 18, 2019 04:45 AM 2 226 Oct 18, 2019 04:45 AM
Last Post: friiz1337
[Python] by datguy.devFeb 23, 2019 05:19 PM 0 125 Feb 23, 2019 05:19 PM
Last Post: datguy.dev