Results 1 to 2 of 2
  1. #1
    ericj5555 is offline Member
    Join Date
    Oct 2012
    Posts
    3
    Rep Power
    0

    Default Problem with creating a triangle out of integers...

    So the program compiles and runs fine, but I'm stuck on figuring out the command/code to print the triangle using the 2nd digit of a two-digit number.
    For example, if the user enters 12, the program currently shows
    12
    1212
    121212

    and so forth.

    Where I would want it to use the 2nd digit only, showing
    2
    22
    222
    2222. etc etc etc.

    Any guidance would be greatly appreciated!


    Java Code:
    import java.util.Scanner;
    public class TriangleOfDigits
    {
        public static void main(String []a)
        {
        Scanner kbd = new Scanner(System.in);
    	System.out.println("Enter an integer from 1 to 12:");
    	int b = kbd.nextInt();
    	int j;
    	int i;
        System.out.println();
    	for(j=0; j<=b; j++)
            {
                for(i=0; i<=j; i++)
                {
                System.out.print(b);
                }
                System.out.println();
    	    }
    	    for (j=b-1; j>=0; j--)
                {
                for (i = j-1; i>=0; i--)
    	    {
    	    System.out.print(b);
    	    }
                System.out.println();
    	}
        }
    }

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default Re: Problem with creating a triangle out of integers...

    Have you heard of mod?

Similar Threads

  1. Replies: 4
    Last Post: 03-15-2012, 07:55 PM
  2. pascal's triangle like problem
    By kulangotski in forum New To Java
    Replies: 4
    Last Post: 12-05-2010, 08:15 AM
  3. While loop triangle problem
    By cmb3587 in forum New To Java
    Replies: 4
    Last Post: 03-02-2009, 12:53 PM
  4. Java Zelda Triangle Problem
    By Hevonen in forum New To Java
    Replies: 3
    Last Post: 10-12-2008, 08:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •