Question

In: Computer Science

(This is for java) I need to rewrite this code that uses a while loop. public...

(This is for java)

I need to rewrite this code that uses a while loop.

public class Practice6 {
     public static void main (String [] args) {

        int sum = 2, i=2;

       do {
sum *= 6;
   i++;
   } while (i < 20);

System.out.println("Total is: " + sum);

}

Solutions

Expert Solution

The Program code in while Loop is :

//Java Programming Using while loop
public class Practice6
{
   public static void main(String[] args)
   {
       int sum = 2, i=2;
while (i < 20)
{
sum *= 6;
i++;
}

System.out.println("Total is: " + sum);
   }
}


Related Solutions

Can you rewrite this MATLAB code using a for loop instead of a while loop? %formatting...
Can you rewrite this MATLAB code using a for loop instead of a while loop? %formatting clc, clear, format compact; %define variables k=1; b=-2; x=-1; y=-2; %while loop initialization for k <= 3 disp([num2str(k), ' ',num2str(b),' ',num2str(x),' ',num2str(y),]); y = x^2 -3; if y< b b = y; end x = x+1; k = k+1; end
Java Programming - please read the description I need this description. Inside a do/ while loop...
Java Programming - please read the description I need this description. Inside a do/ while loop (while choice !='x') , create a method call that calls a switch menu with 3 cases for variable choice and X for exit application.(this is a user input) Each case calls other methods. One of those methods asks for user input float numbers to calculate addition. And the result return to another method that displays the result. Thanks for your help! Thanks for asking....
Re-write following while loop into Java statements that use a Do-while loop. Your final code should...
Re-write following while loop into Java statements that use a Do-while loop. Your final code should result in the same output as the original code below. int total = 0; while(total<100) { System.out.println("you can still buy for"+(100-total)+"Dollars"); total=total+5; }
JAVA PROGRAMMING Hi! I need to create a calculator using do/while loop that calls a menu...
JAVA PROGRAMMING Hi! I need to create a calculator using do/while loop that calls a menu switch where the user choice the calculation type. In the switch each case calls a method to each type of calculation (addition/subtraction/division/multiply/ change set of numbers in the array) those methods sends back the result to be displayed in another method. This application needs to hold the user input's numbers as an array. Thanks for your time. It is a great help!
Trying to complete this in Java. Application called 'Coffee Shop' that uses a while loop to...
Trying to complete this in Java. Application called 'Coffee Shop' that uses a while loop to build a customer order. The Coffee Shops sells: Coffee ($3.25), Espresso ($4.25), and Tea ($2.75). The coffee selection presents the customer with the choices of iced (no charge), cream (50 cents), and sugar (50 cents). The espresso selection presents the customer with choice of caramel (no charge) and chocolate (no charge) with one shot (no charge) or two shots ($1.25) of espresso. Once the...
Write a Java program that uses a while loop to do the following: Repeatedly asks the...
Write a Java program that uses a while loop to do the following: Repeatedly asks the user to enter a number or -1 to exit the program. Keeps track of the smallest and largest numbers entered so far: You will need a variable for the smallest number and another variable for the largest number. Read the first number the user enters, and if it is not -1 set the smallest and largest variables to that number. Use a loop to...
NEED TO REWRITE THIS IN OOP MODE ######## HOMEWORK 19 ###### Rewrite the code in the...
NEED TO REWRITE THIS IN OOP MODE ######## HOMEWORK 19 ###### Rewrite the code in the OOP mode (class mode). ########################### lambda trick ##### first: changing label properties: after you've created a label, you ##### may want to change something about it. To do that, use configure method: ## label.configure(text = 'Yes') ## label.configure(bg = 'white', fg = 'black') ### that change the properties of a label called label. ################################################### ## from tkinter import * abc = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' def callback(x):...
every code should be in java Program 1: Write a while loop that sums the integers...
every code should be in java Program 1: Write a while loop that sums the integers from 1 to 10, excluding 3 and 6. Print the sum. [Hint: Use logical operators] Program 2: Write a for loop that attempts to display the numbers from 1 to 10, but terminates when the control variable reaches the value 6. Program 3: Write a do...while loop that prints the integers from 10 to 0, inclusive.
I need a full java code. And I need it in GUI With the mathematics you...
I need a full java code. And I need it in GUI With the mathematics you have studied so far in your education you have worked with polynomials. Polynomials are used to describe curves of various types; people use them in the real world to graph curves. For example, roller coaster designers may use polynomials to describe the curves in their rides. Polynomials appear in many areas of mathematics and science. Write a program which finds an approximate solution to...
JAVA JAVA JAVA Hey i need to find a java code for my homework, this is...
JAVA JAVA JAVA Hey i need to find a java code for my homework, this is my first java homework so for you i don't think it will be hard for you. (basic stuff) the problem: Write a complete Java program The transport Company in which you are the engineer responsible of operations for the optimization of the autonomous transport of liquid bulk goods, got a design contract for an automated intelligent transport management system that are autonomous trucks which...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT