In: Computer Science
"After the first calculation is performed, the program should ask the user if they would like to continue. They will type in the word “quit” if they wish to end the program. If they wish to continue, they will enter yes than enter a new length of a triangle side and the string they would like on their sign."
How could I show this in code? Please give examples asap. I don't understand loops at all. In java please
/*********************LoopControl.java*********************/
import java.util.Scanner;
/**
* The Class LoopControl.
*/
public class LoopControl {
/**
* The main method.
*
* @param args the arguments
*/
public static void main(String[] args) {
Scanner scan = new
Scanner(System.in);
String option = "yes";
while(option.equalsIgnoreCase("Yes")||option.equalsIgnoreCase("y"))
{
System.out.print("Enter triangle side: ");
int side =
scan.nextInt();//not consume the full line
scan.nextLine();//consume rest of that line including newline
System.out.print("Enter Sign: ");
String sign =
scan.nextLine();
System.out.println("You have entered side = "+side+" and sign =
"+sign);
System.out.println("Do you want to continue:(Y/N): ");
option =
scan.nextLine();
}
scan.close();
}
}
/***************output***************/
Enter triangle side: 343
Enter Sign: dfhd
You have entered side = 343 and sign = dfhd
Do you want to continue:(Y/N):
yes
Enter triangle side: 5454
Enter Sign: dfdfd
You have entered side = 5454 and sign = dfdfd
Do you want to continue:(Y/N):
n
Please let me know if you have any doubt or modify the answer, Thanks :)