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:

Code:

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.

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.