java - How do I return a character an inputted number of times? -
this question has answer here:
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 me taking note of want do. if user puts in number x, how return * character many times?
you can't return in main (it's void method). aren't using length, , if understand question use stringbuilder , simple for loop. print contents of stringbuilder. like
public static void main(string[] args) { scanner sc = new scanner(system.in); int x = sc.nextint(); stringbuilder sb = new stringbuilder(); (int = 0; < x; i++) { sb.append('*'); } system.out.println(sb.tostring()); }
Comments
Post a Comment