Hello there
I am beginning in java, and can't figure out what is wrong with my code
Right now I am learning about loops
and I got stuck in assignment name " running the race "
assignment is following
write the program that asks for the names of 3 runners, and the time in minutes it took each of them to finish the race. the program should display names of the runners in the order.
problem is:
when I run program. First it goes right asks me name of runner and then time
and, then when it goes second time on loop instead of asking me name of the runner first and then time it does both simultaneously
example:
Enter runner's name
Leo
Enter runner's time
44
Enter runner's name
Enter runner's time
Code is bellow:
import java.util.Scanner; class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String name; double time ; int runner = 0; while( runner < 3) { System.out.println("Enter runner's name "); name = sc.nextLine(); System.out.println("Enter runner's time "); time = sc.nextDouble(); runner ++ ; } } }