In: Computer Science
Multiples(): Takes an int (n) as parameter and prints first 10 multiples n in a single line using for loop.
Code in Java
Ex output:
5
5,10,15,20,25,30,35,40,45,50
Java code:
import java.util.Scanner;
public class Main{
//initializing Multiples function
static void Multiples(int n){
//loop to print first 9 multiples
for(int i=1;i<=9;i++)
//printing each multiple and comma
System.out.print((n*i)+",");
//printing last multiple
System.out.print(10*n);
}
public static void main(String[] args){
Scanner input=new Scanner(System.in);
//accepting n from user
int n=input.nextInt();
//calling Multiples function for n
Multiples(n);
}
}
Screenshot:
Input and Output: