java - Creating an alternating tile floor with a nested loop -


I am trying to create a program that designs an alternative tile with user input. To wit. If the use of input 3 will result in 3x3 design which looks like this:

  | R | B R | | B R | B | R | B R |   

I'm having trouble getting the right amount of tiles for the output 3 for the input of 3, the additional "| R |" in line 2 And a 4th row is created later. The output comes from:

  | R | B R | | B R | B R | | R | B R | | I have attached my code below. I know that there is something to do with it:  
  if (r% 2 == 0) {System.out.println ("|"); System.out.print ("| B");   

Any ideas? import java.util. *; Public class tile floor { Public static zero main (string [] algs) {// TODO auto-generated method stub scanner input = new scanner (System.in); System.out.println ("Enter X:"); Int x; X = input .nextInt (); if (x and lt; 10) {int c = 0; int r = 0; while (r; lt; x) {while (c & lt; x) {if (c% 2 == 0 ) System.out.print ("| R"); Else if (c% 2! = 0) System.out.print ("| B"); c ++;} // And 'while (C & LT; X) 'Loop if (R = 2 == 0) {System.out .println ("|"); System.out.print ("| B"); } And if (R% 2! = 0) System.out.println ("|"); C = 0; R ++; } // And 'while (r & lt; x)' loop} // and if input input input.close (); } // end main} // end class

try it < Ex> Import java.util. *; Square tile floor {public static zero main (string [] algs) {// Todo auto-generated method stub scanner input = new scanner (System.in); System.out.println ("Enter X:"); Int x; X = input.nextInt (); Int count = 0; If (x & lt; 10) {int c = 0; Int r = 0; While (R & lt; x) {if (r% 2 == 0) {count = 0; } And {count = 1; } While (c & lt; x) {if (count% 2 ==} {System.out.print ("| R");} and {System.out.print ("| B");} Calculation + +; C ++;} // end 'while (c & lt; x)' loop system out.printLine ("|"); c = 0; r ++;} // and 'while (R & LT ; X) 'loop} // and if statement input input.close ();} // and main} // and class

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -