I need to output number diamond using nested for loops.

Ads

 
 

Share on Google+Share on Google+

Jiawei Tan
I need to output number diamond using nested for loops.
1 Answer(s)      6 years and 6 months ago
Posted in : Java Interview Questions
How to i output this using nested for loops

    1
   131
  13531
 1357531
135797531
 1357531
  13531
   131
    1
Ads
View Answers

May 24, 2011 at 4:20 PM


class Pyramid{
public static void main(String[] args){
    for(int row = 1; row <= 5; row++){
for(int col = 4; col >= row; col--){
System.out.print(" ");
}
for(int col2 = 1; col2 <= row*2; col2+=2){
System.out.print(col2);
}
for(int col3 = row*2-3; col3 >= 1; col3-=2){
System.out.print(col3);
}
System.out.println();
   }
   }
  }

Ads









Related Tutorials/Questions & Answers:
I need to output number diamond using nested for loops.
I need to output number diamond using nested for loops.  How to i output this using nested for loops 1 131 13531 1357531 135797531 1357531 13531 131 1
Using Nested loops
Using Nested loops  How to use nested loops in java when I want...[][] array = new int[16][16]; for (int i=1; i<array.length; i++) { for (int j=1; j<array[i].length; j++) { array[i][j] = i*j; System.out.print(" " + array[i][j
Advertisements
nested for loops
nested for loops  Hello all, I have created a program(gui... the totals after each entry, when all I need is just a total of all entries. This is my first time using java and my first time programming, but I am guessing
nested loops
nested loops  please tell input to get the output: 12345 23456 34567 45678
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
Nested Ajax--not getting output
Nested Ajax--not getting output  Hi everyone... I have two.jsp page from that , with the help of ajax i have called three.jsp. So, i have used DIV... time running...when i run One.jsp , with the help of ajax when i call two.jsp.
pattern-using loops
pattern-using loops  Write a program that displays the following pattern ... (use nested loops... A { public static void main(String[] args) { for(int i=0;i<5;i
i need program to insert data in database using javascript
i need program to insert data in database using javascript  please help me
Loops
Loops  by using drjava q1.Write code that uses nested loops to print... that ask user to insert an integer (n) and prints out the factorial (n!) of this number. n! = n (n-1)(n-2)(n-3)â?¦â?¦â?¦1 , n > 0 plzz i need
read string - using loops in Java
read string - using loops in Java  Write a program to read a string composed of an unknown number of words, then count the number of words in the string, and Display the longest and shortest words, with first letter Uppercase
i need to print customer[1] is abcd,cbnb using array
i need to print customer[1] is abcd,cbnb using array  print("code...) { int i=noofcustomers++; customers[i]=new Customer(f,l); } public..."); System.out.println( b.getnoofcustomers()); for(int i=0;i<5;i++) { System.out.println
i need to print customer[1] is abcd,cbnb using array
i need to print customer[1] is abcd,cbnb using array  print("code...) { int i=noofcustomers++; customers[i]=new Customer(f,l); } public..."); System.out.println( b.getnoofcustomers()); for(int i=0;i<5;i++) { System.out.println
i need to print customer[1] is abcd,cbnb using array
i need to print customer[1] is abcd,cbnb using array  print("code...) { int i=noofcustomers++; customers[i]=new Customer(f,l); } public..."); System.out.println( b.getnoofcustomers()); for(int i=0;i<5;i++) { System.out.println
i need to print customer[1] is abcd,cbnb using array
i need to print customer[1] is abcd,cbnb using array  print("code...) { int i=noofcustomers++; customers[i]=new Customer(f,l); } public..."); System.out.println( b.getnoofcustomers()); for(int i=0;i<5;i++) { System.out.println
i need a school appication using struts frame work with oracle 10g using myeclipse6.0
i need a school appication using struts frame work with oracle 10g using myeclipse6.0   hi i need a school apllication using struts frame work backend 10g xe using myeclipse 6.0
i want to do a project using jsp and servlet....What are all the materials i need to study
i want to do a project using jsp and servlet....What are all the materials i need to study   i want to do a project using jsp and servlet....What are all the materials i need to study ?   Please visit the following
loops
loops  I need the program output 55555 4444 333 22 1 like this by using for loop and if condition only
Solve using only Javascript loops...
Solve using only Javascript loops...  Write a JavaScript code, 1) to find a number of unique letters in string. (Eg. if keyword is unique, Unique...; sortedArray.length; i++){ count++; } document.write("Number
I/O Program output error
I/O Program output error  Hello All, I am working on a program... file, but I am getting incorrect output. I have been successfull with part of the program in that it reads the text file and analyzes it, however I need it to take
i need a help in this please
i need a help in this please  The factorial of a nonnegative integer...) Write an application that computes the value of ex by using the formula ex = 1...=new Scanner(System.in); System.out.print("Enter Number: "); int m
Loops
Loops  ??Using for loops, Write a program to simulate a clock countdown. The program prompts the user to enter the number of seconds, displays... System.currentTimeMillis() which return the number of milliseconds since the epoch
Java repeat string without using loops
Java repeat string without using loops In this section, you will learn how to repeat string without using for loops. The given example accepts the number of times and iterates the string to the number of times set by the user without
How do i get the number of online users from a site using jsp?
How do i get the number of online users from a site using jsp?  Hi, Can any one tell me how to get the number of records from a database dynamically, when each person got logged into the page in jsp
Creating custom output using XMLUnit - MatchTracker duplicates the output data
Creating custom output using XMLUnit - MatchTracker duplicates the output data  how to create a custom output using xmlunit, I have tried it and used... in input xml and I am having duplicate data in output
I need an example of sessionfactory
I need an example of sessionfactory  Hi, I need an example of session factory in hibernate. If you can provide me one with, that would be great...Thanks
Nested If Statement
. Here we are providing you an example using Nested-If statement. In the example, we... Nested If Statement       In this section you will study about the Nested-if Statement in jsp
Java reverse words in a string using only loops
Java reverse words in a string using only loops In this tutorial, you will learn how to reverse words in a string without using any inbuilt methods like split() etc, StringTokenizer functiom or any extra ordinary function Only loops
print 100 numbers using loops
print 100 numbers using loops  how to print from 1 to 100 using...{ public static void main(String[] args){ for(int i=1;i<=100;i++){ System.out.println(i); } } } Thanks   Hi Friend
print rectangle triangle with ?*? using loops
print rectangle triangle with ?*? using loops   * * * * * * i want print like this.what is the code?   import java.lang.*; class Traingles { public static void main(String args[]) { for(int i=1;i<=5
output using SQL
output using SQL  how to get ( 15 march 2011) and (15/03/2011) output using SQL   Use the following queries to get the data from database in the given format. For (15 march 2011) format: SELECT DATE_FORMAT(dob, '%d
i need help plz .... Quickly
i need help plz .... Quickly   how can i count how many numbers enterd by the user so the output would be like this Total number of Scores...; int numberOfScores ; // number of scores entered by the user .. int Scores

Ads

 
Advertisement null

Ads