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 final method in java?
What is an abstract class and what is it’s purpose?
What is the Scope of Static Variable?
What is import java util arraylist?
Explain the difference between private, public, package and protected in java?
In which language java is written?
What is main method?
What are the differences between string, stringbuffer and stringbuilder?
what is platform dependent translation and platform dependent programming language
How do you avoid global variables?
what is abstract class in Java?
What is difference between array and vector?