how to create a (*)pyramid using java codes???

Answers were Sorted based on User's Feedback



how to create a (*)pyramid using java codes???..

Answer / yun hin

class pyramid{
public static void main(String args[]){
int height = 5; //Accept as Input parameter

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("* ");
}
System.out.print("*");
System.out.println();
}
}
}

Is This Answer Correct ?    61 Yes 19 No

how to create a (*)pyramid using java codes???..

Answer / anandh

Enter the height
10
Enter the height of pyramid:
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * *
* * * * * * * * * *

Is This Answer Correct ?    21 Yes 5 No

how to create a (*)pyramid using java codes???..

Answer / shanu

import java.io.*;//package inherited from java class
import java.lang.*;
import java.util.*;
public class Pyramid
{
public static void main(String args[])throws IOException
{
System.out.println("Enter the height");
Scanner cin=new Scanner(System.in);
int n=cin.nextInt();
System.out.println("Enter the height of pyramid:");
for(int i=1;i<=n;i++){
for(int j=1;j<=(n-i);j++){
System.out.print(" ");
}
for(int k=1;k<i;k++){
System.out.print("* ");
}
System.out.print("*");
System.out.println();
}
}
}

Is This Answer Correct ?    16 Yes 3 No

how to create a (*)pyramid using java codes???..

Answer / bigot1988

import java.io.*;//package inherited from java class

public class pyramid
{
public static void main(String s[])throws IOException/*
This is an exception thrown to take the input from buffered
reader class*/
{
int i,j,k,n;
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Enter the height of pyramid:");
n=Integer.parseInt(br.readLine());

for(i=0;i<n;i++)
{
for(j=n;j<n-i;j--)
System.out.print(" ");

for(k=0;k<i;k++)
System.out.print("*");

System.out.println();
}
}
}

Is This Answer Correct ?    17 Yes 14 No

how to create a (*)pyramid using java codes???..

Answer / bigot1988

import java.io.*;//package inherited from java class

public class pyramid
{
public static void main(String s[])throws IOException/*
This is an exception thrown to take the input from buffered
reader class*/
{
int i,j,k,n;
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Enter the height of pyramid:");
n=Integer.parseInt(br.readLine());

for(i=0;i<n;i++)
{
for(j=n;j<n-i;j--)
System.out.print(" ");

for(k=0;k<i;k++)
System.out.print("*");

System.out.println();
}
}
}

Is This Answer Correct ?    14 Yes 14 No

Post New Answer

More J2SE Code Interview Questions

write a program that inputs two real numbers then exchanges their values.

7 Answers   Infosys,


In java, why do we set thread priority, when we know that there is no guarantee by which a thread should be execute?

0 Answers   Google, Microsoft,


write a java program to create a Frame with three scrolls, change the back ground color of the frame using functions with values of scrolls.

0 Answers  


How can we get the details for printing the employee details at run time using JDBC connectivity? can u provide the coding for that? Its urgent?

2 Answers  


How Can I Trace A Java Program . Please Give Me Step by Step Process

1 Answers   IBM,






Write a java program to display multiplication table in a Frame.

1 Answers  


is public static void main() work in java?is "String arg[]" needed as argument?

4 Answers   Tech Mahindra,


1+(2*3)+(4*5*6)+(7*8*9*10)+... specified input value

1 Answers   MAQ,


For printing a message we use System.out.println in normal programs. We use String msg="text....."; Can't we use String msg=" " in normal programs and System.out.println("........") in applets. Please answer this question?

0 Answers  


what is runtime class?

0 Answers   MAQ,


what are the other loops except for for,while,do while and until?

0 Answers   Aricent,


I am trying to pass the string firstName from a Servlet called SampleServet. I am running this on eclipse and it tells me that "the value for annotation attribute must be a constant expression. I don't understand why it is giving me this error. @PersonAnnotation(name = SampleServlet.firstName) public class AnnotationClass{

0 Answers  


Categories