Nested Loop

Nested Loop

Hi, Can anyone tell me example of Nested loop in Java? Thanks
View Answers

April 25, 2008 at 7:26 PM

Hi friend,


public class NestedExample{

public static void main(String[] args){
/** Print Pattern I */
System.out.println("This is First Pattern.");
for(int row = 1; row <= 6; row++){
for (int column = 1; column <= row; column++)
System.out.print(column + "");
System.out.println();
}
System.out.println();
System.out.println();
// Print pattern II
System.out.println("This is Second Pattern.");
for (int row = 6; row >= 1; row-- ){
for ( int column = 1; column <= row; column++ )
System.out.print(column + "" );
System.out.println();
}
System.out.println();
System.out.println();
/** Print Pattern III */
System.out.println("This is Third Pattern.");
for (int row = 1; row <= 6; row++){
for (int space = 6; space > row; space-- )
System.out.print(" ");
for (int column = 1; column <= row; column++ )
System.out.print( column + "" );
System.out.println();
}
System.out.println();
System.out.println();

/** Print Pattern IV */
System.out.println("This is Fourth Pattern.");
for (int row = 6; row >= 1; row-- ){
for (int space = 6; space > row; space-- )
System.out.print( " " );
for (int column = 1; column <= row; column++ )
System.out.print( column + "" );
System.out.println();
}
System.out.println();
System.out.println();
}
}









Related Tutorials/Questions & Answers:
nested for-loop
nested for-loop  hi.write a program that will prompt the user for a positive integer(num) and then display two triangles with num number of lines to represent the following patterns of asterisks. the input num must be validated
Nested Loop - Java Beginners
Nested Loop  Hi, Can anyone tell me example of Nested loop in Java? Thanks   Hi friend,public class NestedExample{ public static void main(String[] args){ /** Print Pattern I */ System.out.println("
Advertisements
loop
loop  what is the difference b/w do while,while and for loop..with example
loop
loop  i want to write my name(inder) through loop in java using star
for loop
for loop  what is for loop   Loops are used for iteration... for a number of times it is finite loop and if repetition is done infinitely it is infinite loop. Java provides several loop structures for iteration. Those
For loop
For loop  Hi! Please explain the following loop: for(i=0;i<a[j];i++) THANX!!   Please reply as soon as possible
for loop
for loop  how to performs the for loop when 2 inputs given like displays the triangle shape and how to take initial values or declaration values plz explain in detailed ex. 1 12 123 1234
Loop
to understand a loop my quesiton are: what du i do wrong in my code since.... (made in blueJ) Class Loop public void loopUpGeneral(int start, int stop... dk  Hi, Please check the for loop once again: for (int i
For Loop
For Loop  Write a program using a for loop that computes the following sum: 1/2 + 2/2 + 3/2 + 4/2 + 5/2 + ... N/2 N will be an integer limit the user enters. This is an example of my upcoming quiz. I need help on knowing
loop
loop  strong textHello can someone help me with this problem,I need to output the following code using a loop the code is as follows with the user inputs in inverted commas,thanks. ENTER CODE(XX to Stop) CODE:"D24" QUANTITY:"2
for loop
for loop  using only two for loop how can print below numbers 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 6 6 6 6 6 6 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9 8 8 8 8 8 8 8 8 7 7 7 7 7 7 7 6 6 6 6 6 6 5 5 5 5
for loop
for loop  using only two for loop how can print below numbers 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 6 6 6 6 6 6 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9 8 8 8 8 8 8 8 8 7 7 7 7 7 7 7 6 6 6 6 6 6 5 5 5 5
for loop in java
for loop in java  54321 4321 321 21 1 using for loop or nested 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 5 4 3 2 1 4 3 2 1 3 2 1 2 1 1 using for loop or nested... 8 9 6 7 8 9 10 all for loop code plz friends guide me
for loop in java
for loop in java  54321 4321 321 21 1 using for loop or nested 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 5 4 3 2 1 4 3 2 1 3 2 1 2 1 1 using for loop or nested... 8 9 6 7 8 9 10 all for loop code plz friends guide me
for loop in java
for loop in java  54321 4321 321 21 1 using for loop or nested 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 5 4 3 2 1 4 3 2 1 3 2 1 2 1 1 using for loop or nested... 8 9 6 7 8 9 10 all for loop code plz friends guide me
for loop in java
for loop in java  54321 4321 321 21 1 using for loop or nested 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 5 4 3 2 1 4 3 2 1 3 2 1 2 1 1 using for loop or nested... 8 9 6 7 8 9 10 all for loop code plz friends guide me
for loop in java
for loop in java  54321 4321 321 21 1 using for loop or nested 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 5 4 3 2 1 4 3 2 1 3 2 1 2 1 1 using for loop or nested... 8 9 6 7 8 9 10 all for loop code plz friends guide me
Nested class
Nested class  What is nested class?  when a class is defined within another class then such a class is called a nested class. Nested... nested classes are: It is a way of logically grouping classes that are only used
nested loops
nested loops  please tell input to get the output: 12345 23456 34567 45678
nested for loops
that the problem lies with my nested for loop which calculates all information...nested for loops  Hello all, I have created a program(gui) that allows a user to input time and minutes in textfields and then calculates
Nested Clases
Nested Clases  public class Nestclasses { a obj=new a(); public..."; System.out.println("hellwo in nested class"+i+ch); } } } class Outer..."); } } } /*Q:-Here I innner Class Constructor but its not call why i
program to create nested tables
program to create nested tables  program to create nested tables
Nested try
Nested try  Hi, In eclipse without providing input i am getting different outputs ie my exception gets executed first then finally block and vice versa.pl explain me class Demo { static void nestedTry(String args[]) { try
Nested try
Nested try  Each time when i execute this code in eclipse i get different answers pl help me with this code class Demo { static void nestedTry..., visit the following link: Nested Try Example
For..in loop
For..in loop         In this tutorial we will study for..in loop which is similar to for each loop of C#, Java and other popular languages, in this example
Nested classes: Examples and tutorials
Nested classes: Examples and tutorials       Nested classes Here is another advantage of the Java... within another class, such class is called a nested class. Inner classes can
Java for loop
Java for loop  Can a for statement loop indefinitely
The nested class - Java Beginners
The nested class  Hi, What is nested class in Java? What is the benefits of nested class? Write examples of nested class. Thanks   .../java/n/java-nested-class.shtml Thanks
ModuleNotFoundError: No module named 'Nested'
ModuleNotFoundError: No module named 'Nested'  Hi, My Python... 'Nested' How to remove the ModuleNotFoundError: No module named 'Nested'... to install padas library. You can install Nested python with following command
For Loop - Struts
For Loop  Hi, How to use for loop in Struts2. I don't want use.... How to use the For loop in JSP. Thanks, Rajesh.  Hi Rajesh, i am sending simple use of for loop. In this example, you will see the use
for( ) loop in php
for( ) loop in php  Generally, when we use for loop in PHP or any other programming language why we use i++ and not ++i. What is the reason behind
for( ) loop in php
for( ) loop in php  Generally, when we use for loop in PHP or any other programming language why we use i++ and not ++i. What is the reason behind
Limits of "For loop"
Limits of "For loop"  Hi, How can I check the upper limit and lower limit of 'FOR' loop during unit testing using Junit. Thanks & Regards Ankit
How to write a loop and a while loop
How to write a loop and a while loop  How do I write a 1 loop and a 1 while loop for the example code: public boolean isTheFirstOneBigger (int num1, int num2) { if (num1 > num2) { return true
GROUP BY IN NESTED QUERY
GROUP BY IN NESTED QUERY  Hello Every One, Query to use GROUP BY CLAUSE IN NESTED QUERY SELECT STATEMENT in mysql database.If u know please help me.thanks
loop statements
loop statements  write a program that reads from input an interger n and prints the factorial of all numbers between 1 and n
Java nested class example
Java nested class example  Give me any example of Nested Class.   Nested Class: Class defined within another class is called nested class. Nested class is divided into two parts- 1.Static 2.Non-static Static
For Loop in Java
another loop then the second loop is called nested loop. The Syntax for the For Loop... For Loop in Java - Java For Loop Examples & Syntax       The for loop is the type of  looping
loop example
loop example   1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 can you give me the code to get the number pyramid
For Loop/PHP
For Loop/PHP  Write a class called math. It is to have one property... 12345. How would you write this as a loop? Would I need to use the for loop or do/while loop?   PHP Factorial Example: <?php $n = 5; $i = 1; $f
foreach loop in php
foreach loop in php  Foreach loop in php
Need help with nested queries
Need help with nested queries  Hello, Table1 has "id", "votes" columns. Table2 has "id", "Name" column. I need to retrieve Name and its corresponging Votes. I tried with nested queries but its confusing. Can anyone please help
loop program
loop program  please tell me the code for the output 1 2 3foo 4 5bar 6foo 7baz 8 9foo 10 11 12foo 13 14baz 15foo bar 16 17 18foo . .......till 50
For loop java
For loop java  1 1 2 3 1 2 3 4 1 2 3 4 5 1 2 3 3 4 5 4 5 6 7 5 6 7 8 9 6 7 8 9 10
Nested and Inner classes
Nested and Inner classes  What is the significance of Inner Classes and Static Inner Classes? or Why are nested classes used?   Hi Friend... a nested class. Inner class is a non static class declared inside another class.Non
Nested If Statement
Nested If Statement       In this section you will study about the Nested-if Statement in jsp.ADS_TO_REPLACE_1 Nested If statement means to use the if statement inside the other
for loop in java
for loop in java  1 1 2 3 1 2 3 4 1 2 3 4 5 1 2 3 3 4 5 4 5 6 7 5 6 7 8 9 6 7 8 9 10 using for loop in java   Java Number Pattern 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 public class PatternExample{ public static void main
for loop
for loop
Using Nested loops
Using Nested loops  How to use nested loops in java when I want to print the 10 multiples of numbers 2 to 15(in multiplication table)   public class MultiplicationTable{ public static void main(String[] args) { int

Ads