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 a byte array?
What is difference between static class and normal class?
Can string be considered as a keyword?
Given a singly linked list, how will you print out its contents in the reverse order? Can you do it with consuming any extra space?
0 Answers Akamai Technologies,
How do you replace all in word?
What are the override methods in Object class?
2 Answers Tech Mahindra, Wipro,
What are methods and how are they defined?
What is predicate in java?
Why hashmap is used in java?
What is the platform?
What are the characteristics provided in jdk1.6 apart from other versions?
What is the default value of float and double datatype in java?