Results 1 to 5 of 5
  1. #1
    Blakester is offline Member
    Join Date
    Oct 2009
    Posts
    2
    Rep Power
    0

    Default looping problems

    aloha to all who help,

    import java.util.*;
    public class PicturesNext
    {
    public static void main (String[] args)
    {
    for (int x = 0; x<=10; x++)
    {
    System.out.println("X"+ "\n");
    }
    }
    }

    goal is to get X to print first line followed by XX on 2nd, XXX on 3rd and so on until 10.....not sure where to go next.....please help!

  2. #2
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    832
    Rep Power
    6

    Default

    Iam spoon feeding this below code to make u understand what is really happening.........


    public class Test
    {
    public static void main (String[] args)
    {
    int maxNumRows = 10;//maximum number of rows

    for ( int row = 0; row <= maxNumRows; row++ )//inner loop

    {

    for ( int innerrow = 0; innerrow <= row; innerrow++ ) // outer loop

    System.out.print("X");

    System.out.println();

    }

    }
    }
    Ramya:cool:

  3. #3
    DiamondDog is offline Member
    Join Date
    Aug 2009
    Posts
    18
    Rep Power
    0

    Default

    Java Code:
    public class TesterClass
    {
        private static String bigString = "XXXXXXXXXX"; 
    	
    	public static void main(String[] args)
    	{
    		for(int i = 0; i<10; i++)
    		{
    		   System.out.println(bigString.substring(0,i+1));
    		}
    	} // end main method
    
    } // end TesterClass

  4. #4
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Quote Originally Posted by RamyaSivakanth View Post
    Iam spoon feeding this below code ...
    Terrible. And no formatting or code tags as well.

  5. #5
    Blakester is offline Member
    Join Date
    Oct 2009
    Posts
    2
    Rep Power
    0

    Default

    Thank you for this.....I am very new and have to learn online! I used what you gave me and added Scanner input so that I could change the height or maxNumRows

    import java.util.*;
    public class TestTriangle
    {
    public static void main (String[] args)
    {
    int maxNumRows; //maximum number of rows
    Scanner input= new Scanner(System.in);
    System.out.print("Enter height:"); //height of Triangle X
    maxNumRows = input.nextInt();

    for ( int row = 0; row <= maxNumRows; row++ )//inner loop

    {

    for ( int innerrow = 0; innerrow <= row; innerrow++ ) // outer loop

    System.out.print("X");

    System.out.println();
    }
    }
    }


    Thank you again!

Similar Threads

  1. Looping if statements
    By rice in forum New To Java
    Replies: 10
    Last Post: 10-02-2009, 02:50 AM
  2. how to do conditional looping?
    By chennee72 in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 09-09-2008, 12:38 PM
  3. Looping problem
    By Tanilo in forum New To Java
    Replies: 1
    Last Post: 08-01-2008, 06:34 AM
  4. Looping ArrayList
    By hai789 in forum Web Frameworks
    Replies: 5
    Last Post: 05-07-2008, 03:55 AM
  5. looping a function
    By Username in forum New To Java
    Replies: 2
    Last Post: 07-30-2007, 05:37 PM

Tags for this Thread

Posting Permissions

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