Program to print 1
1 2
1 2 3
1 2 3 4 like that
Answers were Sorted based on User's Feedback
Answer / rajesh
public class Triangle {
public static void main(String args[])
{
int i,j,k,sp=30;
for(i=1;i<=5;i++)
{
for(k=0;k<sp;k++)
{
System.out.print(" ");
}
sp=sp-1;
for(j=1;j<=i;j++)
{
System.out.print(" "+j);
}
System.out.println();
}
}
}
| Is This Answer Correct ? | 10 Yes | 1 No |
Answer / yun hin
class triangle{
public static void main(String args[]){
int height = 5;
for(int i=1;i<=height;i++){
for(int j=1;j<=(height-i);j++){
System.out.print(" ");
}
for(int k=1;k<i;k++){
System.out.print(k + " ");
}
System.out.print(i);
System.out.println();
}
}
}
| Is This Answer Correct ? | 7 Yes | 0 No |
Answer / sunil pradhan
public class program1 {
public static void main(String[] args){
for(int i = 1; i<=5 ;i++){
for(int k = 1; k<=i; k++){
System.out.print(k);
}
System.out.println("\n");
}
}
}
| Is This Answer Correct ? | 6 Yes | 2 No |
Answer / yagnik
public static void main(String args[]) throws
UnknownHostException, ClassNotFoundException
{
int count =5;
for(int i=1,h=5; i<count;i++){
for(int k=h;k>=0;k--)
{System.out.print(" ");}
for (int j=1 ;j<=i;j++){
System.out.print
(j);System.out.print(" ");
}
h--;System.out.println();
}
}
| Is This Answer Correct ? | 2 Yes | 0 No |
Answer / vivek
#include<iostream>
using namespace std;
int main()
{
int i,j,n,k;
cout<<"provide the no. of row";
cin>>n;
for(i=1; i<=n; i++)
{
k=n-i;
while(k>0)
{
cout<<" ";
k--;
}
for(j=1; j<i; j++)
cout<<" "<<j<< " ";
cout<<"\n";
}
return(0);
}
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / aditya
public class pattern
{
public static void main(int n)
{
int i,j,k;
for(i=1;i<=n;i++)
{
for(j=n;j>i;j--)
{
System.out.print(" ");
}
for(k=1;k<=i;k++)
{
System.out.print(+k+" ");
}
System.out.println();
}
}
| Is This Answer Correct ? | 0 Yes | 1 No |
Answer / subash chandra bose l
class Tri
{
public static void main(String args[])
{
int i,j,k,sp=30;
for(i=1;i<=5;i++)
{
for(k=0;k<sp;k++)
{
System.out.println(" ");
}
sp=sp-2;
for(j=1;j<=i;j++)
{
System.out.println(" "+j);
}
}
}
}
this will print up to 5 rows and if u want more rows to be
printed you can increase the i<=n where n may be the number
of rows you want to print.
| Is This Answer Correct ? | 3 Yes | 7 No |
What is prime number in java?
What is anonymous class?
How will you print number in reverse (descending) order in BST.
What is qms certification?
What is binary tree in java?
How does system arraycopy work in java?
What is Overriding and how can it be used?
How can you read an integer value from the keyword when the application is runtime in java? example?
What does it mean that a method or field is “static”?
In case of inheritance what is the execution order of constructor and destructor?
What is main method?
Does windows 10 need java?