Program that asks user how many times it wants to loop for (java)

You need to have only one for loop:

import java.util.Scanner;

public class NTC 

public static void main(String[] args)
Scanner kb=new Scanner(;
int loop = 10;
double rate=0;
int time=0;
int count;
double distance = rate*time;
System.out.println("How many times would you like to calculate the distance.");
loop = kb.nextInt(); 
for (count = 0; count < loop; count++) 
 System.out.println("Enter rate");
 rate = kb.nextDouble();
 System.out.println("Enter time");
 time = kb.nextInt();
 System.out.println("The distance is "+(rate*time));

Browse More Popular Posts

Leave a Comment