loops , control structures

loops , control structures

a simple java program to print

                       1
                     1 2 1
                   1 2 3 2 1
                 1 2 3 4 3 2 1
View Answers

March 31, 2011 at 3:15 PM

class Pyramid{
     public static void main(String[] args){
     int x = 4;  
     for(int i = 1; i <= x; i++) {  
     for(int j = 1; j <= x - i; j++)  
     System.out.print("   ");  
     for (int k = 1; k <=i; k++)  
     System.out.print((k>= 10) ?+ k : "  " + k); 
     for (int k = i-1; k >= 1; k--)  
     System.out.print((k >=10) ?+ k : "  " + k);  
     System.out.println();  
    }  
  }
}









Related Tutorials/Questions & Answers:
loops , control structures
loops , control structures  a simple java program to print 1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1
loop, control structures
loop, control structures  a java program to print
Advertisements
PHP Control Structure
Control Structures: Generally a PHP script is made of a series of statements which includes assignment, collection of functions, loop, conditional statements etc. In PHP except the last line we need to put a semicolon after every line
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 a message at every second, and terminates when the time expires. Use method
Loops
Loops  Write code that uses nested loops to print the following patterns: Pattern1: 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 1 2 3 4 5 6 Pattern 2: 1 2 3 4 5 6 1 2 3 4 5 1 2 3 4 1 2 3 1 2 1
Loops
Loops  Write code that uses nested loops to print the following patterns: Pattern1: 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 1 2 3 4 5 6 Pattern 2: 1 2 3 4 5 6 1 2 3 4 5 1 2 3 4 1 2 3 1 2 1
Loops
Loops  by using drjava q1.Write code that uses nested loops to print the following patterns: Pattern1: 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 1 2 3 4 5 6 Pattern 2: 1 2 3 4 5 6 1 2 3 4 5 1 2 3 4 1 2 3 1 2 1 q2.Write code
Structures and unions
Structures and unions  union{ struct{ int i1; char c1; }s1; struct{ int i2; char c2; }s2; }u1; what will be the value of (int)u1.s1.i1-(int)u1.s2.i2 and (int)&u1.s1-(char)u1.s1.c2
structures
looping structures in JavaScript
looping structures in JavaScript  What looping structures are there in JavaScript
ModuleNotFoundError: No module named 'structures'
ModuleNotFoundError: No module named 'structures'  Hi, My Python... 'structures' How to remove the ModuleNotFoundError: No module named 'structures' error? Thanks   Hi, In your python environment you
Loops
3.10. Loops Loops are the essential part of the program that have.... More than one loops can be used several times in a script. Loops makes easy... instructed for repetition of the code. PHP Loops ADS_TO_REPLACE_1 In PHP, like other
loops
Loops
Loops
loops
loops
loops
data structures - Java Beginners
data structures  I have got a project of the subject 'data structures and C++' and the topic is 'types of graphs'. please guide me on this topic and help me finding material of this topic
nested for loops
"); } } } }   Close your loops before going
use of loops and screenshots
use of loops and screenshots  1.how to use loops in netbeans? 2.how to draw a correct screenshot
ModuleNotFoundError: No module named 'loops'
ModuleNotFoundError: No module named 'loops'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'loops' How to remove the ModuleNotFoundError: No module named 'loops'
Java - Declaring variables in for loops
Java - Declaring variables in for loops  Java - Declaring variables in for loops
ModuleNotFoundError: No module named 'data-structures'
ModuleNotFoundError: No module named 'data-structures'  Hi, My... named 'data-structures' How to remove the ModuleNotFoundError: No module named 'data-structures' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'nested_structures'
ModuleNotFoundError: No module named 'nested_structures'  Hi, My... named 'nested_structures' How to remove the ModuleNotFoundError: No module named 'nested_structures' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'nested_structures'
ModuleNotFoundError: No module named 'nested_structures'  Hi, My... named 'nested_structures' How to remove the ModuleNotFoundError: No module named 'nested_structures' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'pygen-structures'
ModuleNotFoundError: No module named 'pygen-structures'  Hi, My... named 'pygen-structures' How to remove the ModuleNotFoundError: No module named 'pygen-structures' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'pygen-structures'
ModuleNotFoundError: No module named 'pygen-structures'  Hi, My... named 'pygen-structures' How to remove the ModuleNotFoundError: No module named 'pygen-structures' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'pyriodic-structures'
ModuleNotFoundError: No module named 'pyriodic-structures'  Hi, My... named 'pyriodic-structures' How to remove the ModuleNotFoundError: No module named 'pyriodic-structures' error? Thanks   Hi
ModuleNotFoundError: No module named 'pyriodic-structures'
ModuleNotFoundError: No module named 'pyriodic-structures'  Hi, My... named 'pyriodic-structures' How to remove the ModuleNotFoundError: No module named 'pyriodic-structures' error? Thanks   Hi
ModuleNotFoundError: No module named 'py-structures'
ModuleNotFoundError: No module named 'py-structures'  Hi, My... 'py-structures' How to remove the ModuleNotFoundError: No module named 'py-structures' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'py-structures'
ModuleNotFoundError: No module named 'py-structures'  Hi, My... 'py-structures' How to remove the ModuleNotFoundError: No module named 'py-structures' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'redis_structures'
ModuleNotFoundError: No module named 'redis_structures'  Hi, My... named 'redis_structures' How to remove the ModuleNotFoundError: No module named 'redis_structures' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'aa-structures'
ModuleNotFoundError: No module named 'aa-structures'  Hi, My... 'aa-structures' How to remove the ModuleNotFoundError: No module named 'aa-structures' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'bm_structures'
ModuleNotFoundError: No module named 'bm_structures'  Hi, My... 'bm_structures' How to remove the ModuleNotFoundError: No module named 'bm_structures' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'data-structures'
ModuleNotFoundError: No module named 'data-structures'  Hi, My... named 'data-structures' How to remove the ModuleNotFoundError: No module named 'data-structures' error? Thanks   Hi, In your python
File structures and indexes
File structures and indexes  for the following BCNF relations that describe departments in a company and employees Dept(did,dname,location,managerid) Emp(eid,sal) Now for this system the following queries are important: List
Use javascript loops..
Use javascript loops..  Write a Javascript code to create a redirection script based on day of the week
How to read loops in Java
How to read loops in Java  Example that explains how to read loop in Java
LOOPS - Java Interview Questions
LOOPS   how to find out unique number of elements in given array?{1,2,5,3,2,1,1,7,2,3,0,1,5} output is: 1-4 2-3 3-2 5-2 0-1 7-1 i want source code plz help me
ModuleNotFoundError: No module named 'gevent-loops'
ModuleNotFoundError: No module named 'gevent-loops'  Hi, My Python... 'gevent-loops' How to remove the ModuleNotFoundError: No module named 'gevent-loops' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'gevent-loops'
ModuleNotFoundError: No module named 'gevent-loops'  Hi, My Python... 'gevent-loops' How to remove the ModuleNotFoundError: No module named 'gevent-loops' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'gevent-loops'
ModuleNotFoundError: No module named 'gevent-loops'  Hi, My Python... 'gevent-loops' How to remove the ModuleNotFoundError: No module named 'gevent-loops' error? Thanks   Hi, In your python
pattern-using loops
pattern-using loops  Write a program that displays the following pattern ... (use nested loops) * ** * ** * ** *   the correct pattren
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
while loop to for loops
while loop to for loops  I have to change this while loops to for loops and I was wondering if you could help me out. I got the codes just need to know how to change it. int currentNum= num1; while(num1>num2
Use javascript loops..
Use javascript loops..  Write a JavaScript code to find a number of unique letters in string. (Eg. if keyword is Tajmahal, Tajmahal count will be '5' , it only takes these letters T,j,m,h,l , not taken the letter a because
ModuleNotFoundError: No module named 'external-data-structures'
ModuleNotFoundError: No module named 'external-data-structures'  Hi...: No module named 'external-data-structures' How to remove the ModuleNotFoundError: No module named 'external-data-structures' error? Thanks  
ModuleNotFoundError: No module named 'py-data-structures'
ModuleNotFoundError: No module named 'py-data-structures'  Hi, My... named 'py-data-structures' How to remove the ModuleNotFoundError: No module named 'py-data-structures' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'pythonic-data-structures'
ModuleNotFoundError: No module named 'pythonic-data-structures'  Hi...: No module named 'pythonic-data-structures' How to remove the ModuleNotFoundError: No module named 'pythonic-data-structures' error? Thanks  

Ads