Question

In: Computer Science

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

******

Solutions

Expert Solution

Code:

import java.util.Scanner;
public class Main
{
   public static void printStars(int n) //method
   {
       for(int i=0; i<n; i++) //for loop for run n times
           System.out.print("*"); //printing n stars.
   }
   public static void main(String[] args)
   {
       Scanner sc = new Scanner(System.in);
       System.out.print("Enter n value: "); //prompting the user to enter n value.
       int n = sc.nextInt(); //reading n value.
       Main.printStars(n); //calling the method
   }
}


output:

Note: my friend if you have any questions or queries comment below. I am happy to answer your all questions. i will sort out your queries. Thank you my friend.


Related Solutions

(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.
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.
Write a Java program that takes an array of 10 "Int" values from the user and...
Write a Java program that takes an array of 10 "Int" values from the user and determines if all the values are distinct or not. Return TRUE if all the values of the array are distinct and FALSE if otherwise.
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
Write a program in C or in Java, that takes an integer value N from the...
Write a program in C or in Java, that takes an integer value N from the command line, generates N random points in the unit square, and computes the distance separating the closest pair of points. A unit square is a square with sides of length 1, at points (0, 0), (0, 1), (1, 0), and (1, 1). If you wish to avoid the command-line processing, you can just assume you will generate a fixed number of points, say between...
Java 1.Write a method removeEvenLength that takes an ArrayList of Strings as a parameter and that...
Java 1.Write a method removeEvenLength that takes an ArrayList of Strings as a parameter and that removes all of the strings of even length from the list. 2. Given the following Vehicle interface and client program in the Car class: public interface Vehicle{ public void move(); } public class Car implements Vehicle{ public static void main(String args[]) Vehicle v = new Vehicle(); // vehicle declaration } The above declaration is valid? True or False? 3. Java permits a class to...
Write a java method that takes a string and returns an array of int that contains...
Write a java method that takes a string and returns an array of int that contains the corresponding alphabetic order of each letter in the received string: An illustration: the method takes: "Sara" the method returns: {4,1,3,2} another illustration: the method takes: "hey" the method returns: {2,1,3}
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.
Consider the following recursive method in Java public static int mystery(int n) {   if (n ==...
Consider the following recursive method in Java public static int mystery(int n) {   if (n == 0)   return 1;    else    return 4 * mystery (n - 1);   } What is the output of  mystery (3) using the code segment above Show your work on your trace file
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 -...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT