Hi everyone, just started learning Java and I realized a very minor problem.

I am looking to multiply an asterix "*" by a number so that it is longer.

Something like:


String num = "";
num = "*" * 4;
System.out.println (num);

Sould output:


But instead the compiler says that "the * operator cannot be applied to java.lang.String, int. Please help me get this right.

7 Years
Discussion Span
Last Post by stultuske
public class Test {
      public static void main(String args[])
         int num = 0;

         num = '*' * 4;

          System.out.println (num);


use int instead of String and put asterix in a single code
out put :- 168

Edited by mike_2000_17: Fixed formatting


sigh ...
sj5536 ... you may want to think about what you're saying..

Limiter: I assume that you want to print an asterisk n times.

create an empty String Object, and run a loop, that runs n times.
each time you go through the loop, add a '*' to that String Object, and after finishing the loop: print the String Object.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.