Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Counting cells

  1. #1
    Junior Member
    Join Date
    Oct 2010
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Counting cells

    Hi guys, I have a program that prints a rectangle when you type the width and height as command line arguments. I have got it to print out the rectangle but What i am trying to do is make it count each cell and see if its odd/even. If its even, i want it to add another row and column to make it odd So i can make a hole in the middle of the rectangle i.e. miss a cell out:

    int width = Integer.parseInt(args[0]);
    int height = Integer.parseInt(args[1]);
    int count;
    for (int row = 1; row <= height; row++)
    {
    for (int column = 1; column <= width; column++)
    System.out.print("[_]");
    // end the line.
    System.out.println();

    Any help?

    Kind regards

    Shyam


  2. #2
    Member
    Join Date
    Oct 2010
    Location
    Denver, CO
    Posts
    55
    Thanks
    1
    Thanked 30 Times in 29 Posts

    Default Re: Counting cells

    throw this in there before the for loops
    		if(width%2==0) width++;
    		if(height%2==0) height++;

Similar Threads

  1. Im so confused! Counting and Summing
    By captiancd89 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: October 28th, 2010, 06:49 PM
  2. Need help.. Counting Prime #'s up to 50 w/while loop
    By stommy989 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: October 6th, 2010, 05:40 PM
  3. Help with Arrays - Counting elements
    By ShakeyJakey in forum Collections and Generics
    Replies: 7
    Last Post: August 8th, 2010, 04:09 PM
  4. Question: counting
    By miss confused in forum Java Theory & Questions
    Replies: 2
    Last Post: July 30th, 2010, 05:38 PM
  5. how to copy cells to a new sheet of excel with JexcelAPI??
    By 19world in forum File I/O & Other I/O Streams
    Replies: 0
    Last Post: June 15th, 2010, 03:49 AM