java - Printing a diamond - can't enter input? -


i'm trying write program outputs diamond pattern this:

   *   ***  *****   ***    * 

i've started trying first print top half of diamond.

i can input 'totallines' console, can't type when prompts 'character'. why happening?

we've been using joptionpane of our assignments, makes sense i'd having trouble this, can tell reading book, correct.

(and if have time talk me for-loops, i'm pretty sure need work. i'd grateful.)

public static void main(string[] args) {      scanner input = new scanner(system.in);      int totallines, lines, currline = 1, spaces, maxspaces, minspaces, numcharacters, maxcharacters, mincharacters;      string character;      system.out.print("enter total number of lines: ");     totallines = input.nextint();     system.out.print("enter character used: ");     character = input.nextline();      lines = ((totallines + 1)/2);     // spaces = (math.abs((totallines + 1)/2)) - currline;     maxspaces = (totallines + 1)/2 - 1;     minspaces = 0;     // numcharacters = (totallines - math.abs((totallines +1) - (2*currline)));     maxcharacters = totallines;     mincharacters = 1;     spaces = maxspaces;      (currline = 1; currline<=lines; currline++) {         (spaces = maxspaces; spaces<=minspaces; spaces--){             system.out.print(" ");             }         (numcharacters = mincharacters; numcharacters>= maxcharacters; numcharacters++){             system.out.print(character);             system.out.print("\n");         }         }       } 

try using next() instead of nextline().


Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -