samedi 28 février 2015

Printing a checker board with nested loops. [Java]



I'm having issues with getting my code to print. I need to print a checker board with a grid the size of a user input.


Ex. Checker Board with a grid of 5


Here's my code:



import java.util.Scanner;
public class nestedpractice1
{
public static void main(String[] args)
{
Scanner kbinput = new Scanner(System.in);
//Create Size variable
System.out.println("Input a size: ");
int n = 0; n = kbinput.nextInt();

for(int r = 0; r < n; r++)
{
for(int c = 0; c < r; c++)
{
if((r%2) == 0)
{
System.out.print("*");
}
else if((r%1) == 0)
{
System.out.print(" *");
}
}
System.out.println("");
kbinput.close();
}
}
}



Aucun commentaire:

Enregistrer un commentaire