Click here to Skip to main content
15,908,274 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi


I am stuck with one question
Quote:
a program to print n multiples of x, where n and x are integers



Can anyone explain me

What I have tried:

i dont understand in this what i have to do in this
Posted
Updated 18-Oct-22 19:49pm
Comments
Patrice T 27-Mar-20 12:42pm    
You need to talk with your teacher.
Richard Deeming 27-Mar-20 12:54pm    
I guess that's easier said than done at the moment, unless the class is being taught online. :)
Patrice T 27-Mar-20 12:58pm    
What ? you think they don't have phones ? :)

Write a program to
- accept the input of two numbers 'x' and 'n'
- validate that both numbers are integers (whole numbers)
- Create a loop that runs from 0 to n - let's call the loop counter 'i'
- for each iteration of the loop print the value i * x
 
Share this answer
 
You just need to write a loop that takes the two numbers, n and x. The loop should use a local index variable that counts from 1 to n. At each iteration of the loop multiply the local index by the control number, x, and print the result.
 
Share this answer
 
import java.util.*;
public class Source {

public static void main(String[] args) {
int x,n;
Scanner input= new Scanner(System.in);
x=input.nextInt();
n=input.nextInt();

int num=1;
while(num<=n){
System.out.println(x*num);
num++;

}
}


}
 
Share this answer
 
Comments
CHill60 19-Oct-22 3:06am    
Doing someone's homework for them helps no-one

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900