Monday, 15 April 2013

java - Issue with creating a shape with inputs for a row, column and a character to fill the shape -



java - Issue with creating a shape with inputs for a row, column and a character to fill the shape -

i'm accepting integer value rows , columns, string value character. if user enters value of 5 row , 2 column character "@" output user should be:

@@

@@

@@

@@

@@

the code have far below, comment is, can't seem loop working create shape inputs entered desired amount of rows , columns using character inputted.

import java.util.*; public class createashape { public static void main(string [] args) { scanner in = new scanner(system.in); string errormessage = "please come in amount in range 1 , 25", result = ""; system.out.print("enter number of rows: "); int r = integer.parseint(in.nextline()); if(r < 1 || r > 25) system.out.println(errormessage); else { system.out.print("enter number of columns: "); int c = integer.parseint(in.nextline()); if(c < 1 || c > 25) system.out.println(errormessage); else { system.out.print("enter symbol use: "); string character = in.nextline(); //continuing here } } system.out.println(result); } }

you need 2 loops. outer loop count rows, , inner loop printing of row using character entered. after print columns of row, need print new line.

something shold it:

for(int = 0; < r; i++) { for(int j = 0; j < c; j++) { system.out.print('@'); } system.out.println(); }

java arrays loops java.util.scanner shapes

No comments:

Post a Comment