Accumulating Totals in a Loop
Summary
In this lab, you add a loop and the...
![subject](/tpl/images/cats/informatica.png)
Computers and Technology, 21.03.2020 06:59 ellemarshall13
Accumulating Totals in a Loop
Summary
In this lab, you add a loop and the statements that make up the loop body to a Java program that is provided. When completed, the program should calculate two totals: the number of left-handed people and the number of right-handed people in your class. Your loop should execute until the user enters the character X instead of L for left-handed or R for right-handed.
The inputs for this program are as follows: R, R, R, L, L, L, R, L, R, R, L, X
Variables have been declared for you, and the input and output statements have been written.
Instructions:
Ensure the file named LeftOrRight. java is open.
Write a loop and a loop body that allows you to calculate a total of left-handed and right-handed people in your class.
Execute the program by clicking Run and using the data listed above and verify that the output is correct.
// LeftOrRight. java - This program calculates the total number of left-handed and right-handed
// students in a class.
// Input: L for left-handed; R for right handed; X to quit.
// Output: Prints the number of left-handed students and the number of right-handed students.
import java. util. Scanner;
public class LeftOrRight
{
public static void main(String args[])
{
Scanner s = new Scanner(System. in);
String leftOrRight = ""; // L or R for one student.
int rightTotal = 0; // Number of right-handed students.
int leftTotal = 0; // Number of left-handed students.
// This is the work done in the housekeeping() method
System. out. println("Enter L if you are left-handed, R if you are right-handed or X to quit.");
leftOrRight = s. nextLine();
// This is the work done in the detailLoop() method
// Write your loop here.
// This is the work done in the endOfJob() method
// Output number of left or right-handed students.
System. out. println("Number of left-handed students: " + leftTotal);
System. out. println("Number of right-handed students: " + rightTotal);
System. exit(0);
} // End of main() method.
} // End of LeftOrRight class.
![ansver](/tpl/images/cats/User.png)
Answers: 3
Another question on Computers and Technology
![question](/tpl/images/cats/informatica.png)
Computers and Technology, 22.06.2019 21:10
Dameas communication challenge is due to which factor
Answers: 2
![question](/tpl/images/cats/informatica.png)
Computers and Technology, 23.06.2019 00:30
Quick pl which one of the following is considered a peripheral? a software b mouse c usb connector d motherboard
Answers: 1
![question](/tpl/images/cats/informatica.png)
Computers and Technology, 24.06.2019 00:40
Use a software program or a graphing utility with matrix capabilities to solve the system of linear equations using an inverse matrix. x1 + 2x2 − x3 + 3x4 − x5 = 6 x1 − 3x2 + x3 + 2x4 − x5 = −6 2x1 + x2 + x3 − 3x4 + x5 = 3 x1 − x2 + 2x3 + x4 − x5 = −3 2x1 + x2 − x3 + 2x4 + x5 = 5
Answers: 3
![question](/tpl/images/cats/informatica.png)
Computers and Technology, 24.06.2019 02:30
Which option completes the explanation for conflict of interest in an organization
Answers: 1
You know the right answer?
Questions
![question](/tpl/images/cats/mat.png)
Mathematics, 12.11.2020 16:50
![question](/tpl/images/cats/istoriya.png)
![question](/tpl/images/cats/mat.png)
![question](/tpl/images/cats/es.png)
![question](/tpl/images/cats/mat.png)
Mathematics, 12.11.2020 16:50
![question](/tpl/images/cats/biologiya.png)
![question](/tpl/images/cats/mat.png)
Mathematics, 12.11.2020 16:50
![question](/tpl/images/cats/mat.png)
![question](/tpl/images/cats/obshestvoznanie.png)
![question](/tpl/images/cats/fizika.png)
![question](/tpl/images/cats/mat.png)
![question](/tpl/images/cats/es.png)
Spanish, 12.11.2020 16:50
![question](/tpl/images/cats/mat.png)
Mathematics, 12.11.2020 16:50
![question](/tpl/images/cats/mat.png)
![question](/tpl/images/cats/mat.png)
![question](/tpl/images/cats/himiya.png)
Chemistry, 12.11.2020 16:50
![question](/tpl/images/cats/biologiya.png)
![question](/tpl/images/cats/obshestvoznanie.png)
Social Studies, 12.11.2020 16:50
![question](/tpl/images/cats/mat.png)