loops , control structures

Ads
 

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();  
    }  
  }
}

Ads









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
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
loops
Loops
Loops
loops
loops
loops
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 '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
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
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
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
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
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

Ads