Question

In: Computer Science

"After the first calculation is performed, the program should ask the user if they would like...

"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

Solutions

Expert Solution

/*********************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 :)


Related Solutions

Write a C++ program, ask the user about which sorting algorithm they would like to use...
Write a C++ program, ask the user about which sorting algorithm they would like to use in order to sort the vector. The four sorting algorithms your program should implement are: selection sort, merge sort, quick sort, and insertion sort. Once a sorting algorithm is selected, your program should display step by step every change that the sorting algorithm does on its journey to completely sorting the integer values of the vector Your output file should then contain the sorted...
Question: Conversion Program * This program will ask the user to input meters * After input,...
Question: Conversion Program * This program will ask the user to input meters * After input, a menu will be displayed: * 1. Convert to kilometers * 2. Convert to inches * 3. Convert to feet * 4. Quit * * The user will select the conversion and the converted answer will be displayed. * The program should redisplay the menu for another selection. * Quit program when user selects 4. Hi, my instructor requirement fix the bug in the...
PYTHON Modify the program in section Ask the user for a first name and a last...
PYTHON Modify the program in section Ask the user for a first name and a last name of several people.  Use a loop to ask for user input of each person’s first and last names  Each time through the loop, use a dictionary to store the first and last names of that person  Add that dictionary to a list to create a master list of the names  Example dictionary: aDict = { "fname":"Douglas", "name":"Lee" } ...
what should this program do? Write a program (Lab8.cpp) that will ask the user for two...
what should this program do? Write a program (Lab8.cpp) that will ask the user for two file names. You will read the characters from each file and put them in separate queues. Then, you will read each character from each queue and compare it. If every character from both queues is the same, you will print “The files are identical.” Otherwise, you will print “The files are not identical.” Step-by-Step Instructions Create a character queue (named queue1) using the Standard...
Write a Java program that will first ask the user how many grades they want to...
Write a Java program that will first ask the user how many grades they want to enter. Then use a do…while loop to populate an array of that size with grades entered by the user. Then sort the array. In a for loop read through that array, display the grades and total the grades. After the loop, calculate the average of those grades and display that average. Specifications Prompt the user for the number of grades they would like to...
Python3 Write a program to implement the Pokemon game should ask the user to enter their...
Python3 Write a program to implement the Pokemon game should ask the user to enter their type and compare it with a randomly chosen computer type and correctly display who wins/ties.
USE MATLAB Write a program in Matlab that would continuously ask the user for an input...
USE MATLAB Write a program in Matlab that would continuously ask the user for an input between 1 and 6, which would represent the result of rolling a die. The program would then generate a random integer between 1 and 6 and compare its value to the value entered by user. If the user’s die is larger, it should display, “Mahahanap mo na ang forever mo. Sana all!” If the user’s die is smaller, it should display, “Gising na friend,...
Write a Java program to do the following: Ask the user to enter 10 first names...
Write a Java program to do the following: Ask the user to enter 10 first names (one word - no hyphen or apostrophe) using the keyboard. 1) Display the list of names one per line on the Console. 2) Display the names again, after eliminating duplicates using a HashSet (Your code MUST use HashSet).
Create a Netbeans project called LineNumbers The program should do the following: –Ask the user for...
Create a Netbeans project called LineNumbers The program should do the following: –Ask the user for how many lines of text they wish to enter –Declare and initialize an array of Strings to hold the user’s input –Use a while loop to prompt for and read the Strings (lines of text) from the user at the command line. Typically, this would be a 'for' loop since we know the number of times to execute the loop based upon the number...
The JAVA program should do the following: –Ask the user for how many lines of text...
The JAVA program should do the following: –Ask the user for how many lines of text they wish to enter –Declare and initialize an array of Strings to hold the user’s input –Use a while loop to prompt for and read the Strings (lines of text) from the user at the command line. Typically, this would be a 'for' loop since we know the number of times to execute the loop based upon the number supplied by the user, but...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT