Question

In: Computer Science

Multiples(): Takes an int (n) as parameter and prints first 10 multiples n in a single...

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

Solutions

Expert Solution

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:


Related Solutions

Write a function which takes one parameter int num, and prints out a countdown timer with...
Write a function which takes one parameter int num, and prints out a countdown timer with minutes and seconds separated by a colon (:). It should print out one line for each second elapsed and then pause one second before printing out the next line. A few things to note: - You can assume that calling the function usleep(1000000) makes the program pause for one second - It should count down from num minutes:zero seconds to zero minutes:zero seconds -...
Write a java program calls the following methods: a. printStars(): Takes an int (n) as parameter...
Write a java program calls the following methods: a. printStars(): Takes an int (n) as parameter and prints n stars (*) using for loop. ex. 6 ******
Write a subroutine that takes an int (.long) parameter and squares it. The parameter should be...
Write a subroutine that takes an int (.long) parameter and squares it. The parameter should be passed in on the stack. The answer should be returned in eax. The subroutine should not disturb any registers except eax, ecx, and edx. (Save any registers on the stack and restore them before exiting the subroutine.) Upon entry to the subroutine, push ebp, etc., to access the parameter.
This function takes in a string as a parameter and prints the average number of characters...
This function takes in a string as a parameter and prints the average number of characters per word in each sentence in the string. Print the average character count per word for each sentence with 1 decimal precision (see test cases below). Assume a sentence always ends with a period (.) or when the string ends. Assume there is always a blank space character (" ") between each word. Do not count the blank spaces between words or the periods...
C++ A void function named NextLeapYear() that takes an int reference parameter. If the parameter is...
C++ A void function named NextLeapYear() that takes an int reference parameter. If the parameter is positive, the function will assign it the next leap year after it; otherwise, the function will assign 4 to it.
C Write a function int sort(int** arr, int n) that takes as input an array of...
C Write a function int sort(int** arr, int n) that takes as input an array of int pointers, multiplies the ints the pointers point to by -1, and then sorts the array such that the values pointed to by the pointers are in decreasing order. For example, if the array is size 10 the pointer at index 0 will point to the largest value after multiplying by -1 and the pointer at index 9 will point to the smallest value...
(java)Write a recursive method public static int sumForEachOther(Int n) that takes a positive Int as an...
(java)Write a recursive method public static int sumForEachOther(Int n) that takes a positive Int as an argument and returns the sum for every other Int from n down to 1. For example, sumForEachOther(8) should return 20, since 8+6+4+ 2=20.And the call sumForEachOther(9) should return 25 since 9+7+5 + 3+1-=25. Your method must use recursion.
Define a function called 'filterWords, which takes a parameter. The first parameter, text" is an nltk.text.Text...
Define a function called 'filterWords, which takes a parameter. The first parameter, text" is an nltk.text.Text object. The function definition code stub is given in the editor. Perform the given operation for the 'text' object and print the results: • Filter the words whose length is greater than 15 from the complete set of 'text', and store into "large_words' variable as a list
A function calledsumOfFactorsthat takes n as a parameter and then returns the sum of the proper...
A function calledsumOfFactorsthat takes n as a parameter and then returns the sum of the proper factors/divisors ofn; for example,the sum of factorsof 20= 10+5+4+2 = 21.Note that 1 is nota properfactor of any number.Sample command => output:(display (sumOfFactors20))=> 21Hint: Calla recursivefunction sum_helperfrom sumOfFactorsfunction as follows:(define (sumOfFactors n)(sum_helper n (-n 1)))Here sum_helperfunction takes two parameters: n, d and returns the sum of all factors of n whichare <= d; for e.g. (sum_helper 20 6) returnsall proper factors of 20 which...
Array & Function - Can I pass a single parameter to a function that takes two...
Array & Function - Can I pass a single parameter to a function that takes two arguments: data passed from: arrayOne(4); to function: string function (array[], int)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT