-1
import java.util.Scanner;

public class myLine {

public static void main(String[] args) {
    String CurrentLine = new String();
    int length =0;

     Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();

        if (CurrentLine.charAt(0) == 'l') {
            return '*' x times;
        }
    }

}

The last line is just me taking note of what I want to do. If the user puts in a number for x, how do I return the * character that many times?

krock
  • 28,904
  • 13
  • 79
  • 85
  • Did you miss some code when you copied and pasted? You talk about returning, but you didn't post any method that returns anything. Where are you trying to return a String to? – Dan Getz May 31 '15 at 03:16
  • Oh like I said, the last line means nothing code-wise. It's just there to remind me that I want to return a character x number of times which is what I don't know how to do – magicfan04 May 31 '15 at 03:27

1 Answers1

0

You can't return in main (it's a void method). You aren't using length, and if I understand your question you could use a StringBuilder and a simple for loop. Then print the contents of the StringBuilder. Something like

public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < x; i++) {
        sb.append('*');
    }
    System.out.println(sb.toString());
}
Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249