Question

In: Computer Science

Questions: 1) // declare integer variable sum equal to zero // declare variable integer i //...

Questions: 1) // declare integer variable sum equal to zero // declare variable integer i // declare while loop condition where i is less then 25 // inside of brackets calculate the sum of i (addition) // increment i // outside the loop print the sum of values =============================================

2) Create a sentinel value example if I press number 0 it will display the sum of data // create a scanner // prompt the user to to enter the numbers // declare variable integer and relate that to input scanner // declare variable sum equals to zero // declare while loop condition where the variable you just created above is not equal to 0 // inside of the bracket of while condition sum the data with addition // prompt the user to enter integer unless its not zero // again the same variable that you created outside the while condition will ask to input value through scanner // outside the bracket display the sum of values

3) Declare the do while loop // declare the variable integer which is equal to zero // declare do-while loop and inside of brackets prompt the user to print word "Hello" // increment the variable integer that you declared outside the loop // outside brackets declare while condition where variable that you declared in the beginning is less then 25

4) Continue the same process as exercise number 3, but this time use for loop

5) Create break command in while loop // declare integer variables sum and number and both of them are equal to zero // create while condition where number is less then 25 // inside of brackets increment number // declare if condition where number is equal to 10 // write continue ++ // sum the number (addition) // outside of brackets display sum in console

6) In this exercise do the same thing like number 5 exercise but instead of continue ++ write break;

Solutions

Expert Solution

We have declared int sum = 0, Then with the help of while loop, we are going on adding the value of i from 0 to 24, using the condition while(i<25).

The code with output is:

Again, in the second question, we have to ask user to input numbers, and add them, until a zero is pressed. This is checked by a sentinel value in the while condition.

The code and its output is:

In the third question, we have to use a do while loop to input "hello" 25 times. The code and output is:

In the fourth question, we have do the same as third question, but with a for loop


Related Solutions

Update the function playScratchOffs to do the following Declare an integer variable to store the type...
Update the function playScratchOffs to do the following Declare an integer variable to store the type of scratch off (i.e. type) Declare an integer variable to store the number of scratch off (i.e. count) Declare an integer variable for loop control (i.e. c) Declare a variable of data type struct OneDollar (i.e. oneSO) Declare a variable of data type struct TwoDollar (i.e. twoSO) Declare a variable of data type struct FiveDollar (i.e. fiveSO) Write a series of printf statements to...
C++ Program 1. Declare an integer static array a[ ] with 100 elements. 2. Declare an...
C++ Program 1. Declare an integer static array a[ ] with 100 elements. 2. Declare an integer pointer p. 3. Let p pointing to the array a[ ]. 4. Use p (you have to use p) to put 0 into the first element of this array, 2 into the second element, 4 into the 3rd element, 6 into the 4th element, ... 198 into the 100th element of this array. 5. Use a (you have to use a) to display...
The variable smokes is a binary variable equal to one if a person smokes and zero...
The variable smokes is a binary variable equal to one if a person smokes and zero otherwise. Cigprice is the price of cigarettes, white is a dummy variable that takes the value 1 if the person is white and 0 otherwise and restaurn is a dummy that takes the value 1 if the person lives in a state with restaurant smoking restrictions. The estimated linear probability model is smokes = .656 - .069 log(cigpric) + .012 log(income) - .029 educ...
Java language (a) Write code segments to perform the following: (i) declare and create an integer...
Java language (a) Write code segments to perform the following: (i) declare and create an integer array freqArray of size 8 (ii) declare and initialize an array weight (with suitable type) which contains 48.5, 80 and 68 (iii) declare a Mouse array of size 2 with name mouse and initialize it with Mouse objects using one statement (b) A incomplete definition of a class Temperature is given below: public class Temperature { private double value[] = {36.5, 40, 37, 38.3};...
Sum of the deviations from Mean is equal to zero. Check the validity of this statement by taking observations 8. 1 and 6?
Sum of the deviations from Mean is equal to zero.  Check the validity of this statement by taking observations 8. 1 and 6?
1. Declare/define the variable/constant as indicated: a. a variable to store the grade for a student...
1. Declare/define the variable/constant as indicated: a. a variable to store the grade for a student (as whole number) b. a variable to store a letter grade for a course, like A, B, or C c. a variable to store an average for a student (may have decimal places) d. a variable to represent if a student passed the course or not, with a value of TRUE or FALSE e. a constant to represent the passing grade of 65 2....
Why economic growth is not zero-sum?
Why economic growth is not zero-sum?
JAVASCRIPT: /* Assignment 03: Complete this javascript */ // 1) Declare a variable named myValue //...
JAVASCRIPT: /* Assignment 03: Complete this javascript */ // 1) Declare a variable named myValue // Assign myValue the value of "Hello, how's it going?" // Print the value of myValue to the console // 2) Use the charAt() method to display the letter t // from the variable myValue in the console // 3) Use the indexOf() method to display the position of "going" // from the variable myValue in the console // 4) Use the slice() method to...
*I NEED ALL OF THE QUESTIONS ANSWERED* 1.Heat is (a) equal to temperature, (b) the temperature...
*I NEED ALL OF THE QUESTIONS ANSWERED* 1.Heat is (a) equal to temperature, (b) the temperature change divided by the mass, (c) the mass divided by specific heat, (d) the flow of energy due to a temperature difference. 2.The human temperature sense is associated with (a) sight, (b) smell, (c) touch, (d) hearing. 3.Temperature is a relative measure of (a) transferred energy, (b) hotness or coldness,                     (c) internal energy, (d) specific heat. 4.The temperature difference between the ice and steam...
Write a C program to Declare an integer array of size 10 with values initialized as...
Write a C program to Declare an integer array of size 10 with values initialized as follows. int intArray[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; Compute each item of a new array of same size derived from the above array by: adding first item (intArray[0]) of the array with 3rd, 2nd with 4th, 3rd with 5th and so on. For the last-but-one item intArray[8], add it with first item and for the last item (intArray[9])...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT