Write a method Met that takes as parameters an integer and prints the first five multiples of the integer.
Only write the method - assume that the Class & main method have been defined.
Print the multiples on a single line, separated by a space character. At the end of the line, print a new line.
Example Input: 5
Output: 5 10 15 20 25
Example Input: 7
Output: 7 14 21 28 35
Answers
Answered by
12
public static void met(int x){
for(int i=1;i<=5;i++){
System.out.print(x*i);
if(i<5){
System.out.print(" ");
}
else{
System.out.println();
}
}
}
Answered by
5
Solving the program using C++
#include<iostream>
using namespace std;
int main()
{
int a;
cout<<"Enter the value of the number whose multiple you want to find ";
cin>>a;
for(int i=1;i<=5;i++) //loop to print the multiples
{
cout<<a*i; // This will print the multiples of the number of your choice
cout<<" "; //This will provide space between the multiples
}
}
Similar questions
Computer Science,
7 months ago
History,
7 months ago
English,
7 months ago
Math,
1 year ago
Math,
1 year ago
Psychology,
1 year ago