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 in java to solve a system of n-variabled simultaneous equations using the guassian elimination method. let the maximum possible value of n be 100. run the program using hypothetical values for a set of 10- variables simultaneous equations. print out the program, the input equation and the results generated by the program.

0 Answers   TCS,


Why the program getting error if we don't use String args[] in main(), even in the case of not getting any arguments from command line?

1 Answers  


how to print a message to console without using main() function?(do not use even static blocks also.)

14 Answers   Google, Zoho,


Is it possible to define marker interface in java.If possible then how to define user defined marker interface?

1 Answers   Tech Mahindra,


write a program that will ask the user to enter a number n and display the product of all numbers from 1 to n.

1 Answers  






what is runtime class?

0 Answers   MAQ,


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

7 Answers   Infosys,


write a program in java to find the moving average of all prime numbers between 2 and 100.

0 Answers  


Can we run Applet in Web browser with security policy files

0 Answers  


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

0 Answers   Aricent,


Write a program to convert a decimal number to binary form?

1 Answers   Oracle,


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

5 Answers   Infosys,


Categories