Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need to change this program into a FOR loop or just a DO loop and not the whil

ID: 3545025 • Letter: I

Question

I need to change this program into a FOR loop or just a DO loop and not the while and i am having difficulty, can someone please help.



package midterm;

import java.util.Scanner;


public class Ball

{
    
    public static void BallBounce(int x)
    
    {
        
        double vel = x, hei = 0;
    
        int ballbounce = 0;
        
        do
        
        {
            
            
            
            int c = 0;
            
            System.out.println("Time: "+c+"   "+"Height: "+hei);
            
            hei = hei+vel;
            vel = vel -32;
            
            if(hei<0){
                vel = vel*(-0.5);
                hei = hei*(-0.5);
                System.out.println("Ball Bounce");
                ballbounce = ballbounce+1;
            }
            
        }
        
        while(ballbounce<5);
    }
        public static void main(String[] a){
            
            int velocity =0;
            
            Scanner input = new Scanner(System.in);
            
            System.out.println("Please enter an initial velocity: ");    
            
            velocity = input.nextInt();
            
            BallBounce(velocity);
        }
}

Explanation / Answer

package midterm;

import java.util.Scanner;


public class Ball

{

public static void BallBounce(int x)

{

double vel = x, hei = 0;

int ballbounce = 0;

do

{



int c = 0;

System.out.println("Time: "+c+" "+"Height: "+hei);

hei = hei+vel;
vel = vel -32;

for (int i=0,i< hei,i--)


{
vel = vel*(-0.5);
hei = hei*(-0.5);
System.out.println("Ball Bounce");
ballbounce = ballbounce+1;
}

}

for (int i=5,Ball Bounce<i,i--)

{
public static void main(String[] a){

int velocity =0;

Scanner input = new Scanner(System.in);

System.out.println("Please enter an initial velocity: ");

velocity = input.nextInt();

BallBounce(velocity);
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote