Home Answers Viewqa Java-Beginners loops , control structures

 
 


nisha
loops , control structures
1 Answer(s)      2 years and 3 months ago
Posted in : Java Beginners

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 Pages:
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
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
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... using while loop or any other control statements. Example: import
looping structures in JavaScript
looping structures in JavaScript  What looping structures are there in JavaScript
PHP Alternative Control Structure
Alternative Control Structure: PHP provides alternative ways to use control structures like if, else, elseif, for, while, foreach etc. In each control... coding within any control structure, the examples are given below: elseif
Loops - Introduction
will introduce you with the Loops in Java. Loops are very useful in programming... Many loops consist of three operations surrounding the body: (1) initialization... to control whether the body is executed. Scope of loop indicated
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
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 In PHP, like other programming
Loop Control flow enhancement discussion - Java Tutorial
Loop Control flow enhancement discussion 2001-04-28 The Java Specialists... control / Loop Control flow enhancement. I could see someone putting your switch... of loops, do switch statements, or find out what methods you were called from
Java Control Statements
Java Control Statements       Introduction to Control Statements In this section, we are going to discuss the control statements. Different types of control statements
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
C Structure example
; This section illustrates you the concept of structure in C. Structures... or control blocks. A structure is a collection of variables grouped together under... id; char *name; float percentage; }   In structures, we have
Java Control Statements
Java Control Statements     ... the control statements. Different types of control statements: the decision making... and for) and branching statements (break, continue and return). Control
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
Java Software Structures
Java NotesJava Software Structures Java Software Structures: Designing and Using Data Structures, 2/E, by John Lewis and Joseph Chase. Addison Weseley, 2005 Errata, Lacunae, etc p 33 - Erroneously uses new with String
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
Ford and Topp, Data Structures with Java, Errata
Java NotesFord and Topp, Data Structures with Java, Errata This is a list of some of the errors that have been found in the process of teaching a data structures course from it. Chapter 1 Copyleft 2006 Fred Swartz MIT
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
Data structures and algorithmms - Java Server Faces Questions
Data structures and algorithmms  Could u provide me with a solution to assignment COS212Assignment2008.doc on http://www.cs.up.ac.za
Java Data Structures
Java NotesJava Data Structures Term "Collections". The overall term... to the more common Data Structures. In addition to describing general data... that professional programmers implement basic data structures, such as linked lists
Alternative Data Structures
Java NotesAlternative Data Structures Packages have been developed outside of Sun for additional functionality. The following free, GPL, packages fill... shortcomings of the Java Collections data structures: lack of support for primitive data
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
pattern-using loops
pattern-using loops  Write a program that displays the following pattern ... (use nested loops) * ** * ** * ** *   the correct pattren
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
Use javascript loops..
Use javascript loops..  Write a Javascript code, so that numbers appear in following format, 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 1 2 3 4 1 2 3 1 2 1 for n=5. Input 'n' value from user.   Hi Friend, Try
LOOPS !! - Java Interview Questions
LOOPS !!  i have string "Hello" i want to print like H He Hel Hell Hello o ol oll olle olleh i want source code plz help me?  String s="Hello"; System.out.println(s.length()); System.out.println
Arrays, loops and string handling
Arrays, loops and string handling  How would i go about in creating a program to mark and grade a set of multiple choice test results. this is a console program that uses JOptionPane dialog boxes as well. Read a set of 10
calender control
calender control  plz tell me about calender type control in java
Session control
Session control  Could we make session control in JSP language without having any help of other framework