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 6 of 6

Thread: Stripes (asterisk patterns) problem

  1. #1
    Junior Member
    Join Date
    Oct 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Stripes (asterisk patterns) problem

    Hi guys I need to make a program that does stripes, checkerboard, and double diagonal. I can not get the stripes to work any suggestions?
    import java.util.Scanner;
    public class AsciiArt {
    public static void main(String[] args){
    int pattern;
    Scanner input=new Scanner(System.in);
    System.out.println("Choose one of the following patterns by pressing the corresponding number");
    System.out.println("1) Stripes");
    System.out.println("2) Chcker Board");
    System.out.println("3) Double diagonal (aka the X)");
    pattern=input.nextInt();
    int number;
    System.out.println("Input a size (must be larger than 1)");
    number=input.nextInt();
    if(pattern==1){
    for(int i=1;i<=number;i++){
    for(int j=1;j<=number;i++){
    if(j%2==1){
    System.out.print("*");
    }
    else{
    System.out.print(" ");
    }
    System.out.println("");
    }
    }
    }
    }
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,404
    Thanks
    53
    Thanked 2,399 Times in 2,352 Posts

    Default Re: Stripes (asterisk patterns) problem

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE GOES HERE
    [/code]
    to get highlighting and preserve formatting.

    Please post the program's current output, explain what is wrong with it and show what it should be.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Oct 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Stripes (asterisk patterns) problem

    import java.util.Scanner;
    public class AsciiArt {
    	public static void main(String[] args){
    		int pattern;
    		Scanner input=new Scanner(System.in);
    		System.out.println("Choose one of the following patterns by pressing the corresponding number");
    		System.out.println("1) Stripes");
    		System.out.println("2) Chcker Board");
    		System.out.println("3) Double diagonal (aka the X)");
    		pattern=input.nextInt();
    		int number;
    		System.out.println("Input a size (must be larger than 1)");
    		number=input.nextInt();
    		if(pattern==1){
    			for(int row=1;row<=number;row++){
    				for(int column=1;column<=number;column++){
    					if(column%2==1){
    						System.out.print("*");
    					}
    						else{
    							System.out.print(" ");
    						}
    				System.out.println("");
    				}
    			}
    		}
    		else if(pattern==2){
    				for(int row=1;row<=number;row++){
    					for(int column=1;column<=number;column++){
    						if(row+column%2==0){
    							System.out.print("*");}
    						else if((row+column)%2==1){
    							System.out.print(" ");}
    						}
    					System.out.println("");
    					}
    				}
     
    		}		
    	}

    I want to get
    * * *
    * * *
    * * *
    * * *
    * * *
    for the stripes and
    * * *
    _* *
    * * *
    _* *
    * * *
    for the checkerboard

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,404
    Thanks
    53
    Thanked 2,399 Times in 2,352 Posts

    Default Re: Stripes (asterisk patterns) problem

    What does the program write out now?
    Post its output to show what the problem is.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Oct 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Stripes (asterisk patterns) problem

    This is the output right now for stripes
    Choose one of the following patterns by pressing the corresponding number
    1) Stripes
    2) Chcker Board
    3) Double diagonal (aka the X)
    1
    Input a size (must be larger than 1)
    5
    *

    *

    *
    *

    *

    *
    *

    *

    *
    *

    *

    *
    *

    *

    *
    and this is the output for checkerboard
    Choose one of the following patterns by pressing the corresponding number
    1) Stripes
    2) Chcker Board
    3) Double diagonal (aka the X)
    2
    Input a size (must be larger than 1)
    5

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,404
    Thanks
    53
    Thanked 2,399 Times in 2,352 Posts

    Default Re: Stripes (asterisk patterns) problem

    Can you describe what is wrong with the output? What needs to be changed for the program to create the desired output?

    For example:
    The program prints XXXXX on one line
    but it should print XXX on the first line and XX on the second line.

    The code doesn't have any comments so I can not understand what the statements are supposed to do.
    For example what is the following for:
    if(column%2==1){
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Patterns!! Please help!
    By winn1me in forum What's Wrong With My Code?
    Replies: 8
    Last Post: November 14th, 2013, 04:49 PM
  2. Design Patterns
    By keepStriving in forum Java Theory & Questions
    Replies: 3
    Last Post: October 29th, 2013, 11:22 AM
  3. Checkerboard (asterisk pattern) problem
    By jjb1989 in forum Loops & Control Statements
    Replies: 18
    Last Post: September 8th, 2013, 08:52 PM
  4. Asterisk Graph
    By ThatBeast in forum Java Theory & Questions
    Replies: 3
    Last Post: January 4th, 2013, 08:22 PM
  5. Display patterns on the screen
    By finjws in forum Loops & Control Statements
    Replies: 12
    Last Post: February 10th, 2012, 12:11 PM

Tags for this Thread