56.0k views
3 votes
Does anyone know how to make a astronaut hop while using loop?

User Donna
by
5.2k points

1 Answer

4 votes

Answer:

In Java

Step-by-step explanation:

package application;

import java.util.Scanner;

import entities.Astronaut;

public class Main {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.print("How is the astronaut's energy in a scale of 0 to 100? ");

int energy = sc.nextInt();

Astronaut fakeArmstrong = new Astronaut();

while (energy > 0) {

fakeArmstrong.hop();

energy--;

}

System.out.println("The astronaut is tired eh? Let him rest you psychopato");

sc.close();

}

}

----------------------------------------------------------------------------------------------

package entities;

public class Astronaut {

private int bodyEnergy;

public Astronaut() {

}

public int getBodyEnergy() {

return bodyEnergy;

}

public void hop() {

System.out.println("up and down!");

}

}

User Erik Larsson
by
5.3k points