how to create a (*)pyramid using java codes???
Answers were Sorted based on User's Feedback
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 |
Answer / anandh
Enter the height
10
Enter the height of pyramid:
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * *
* * * * * * * * * *
Is This Answer Correct ? | 21 Yes | 5 No |
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 |
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 |
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 |
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?
does anyone know the code to display a triangle using a applet?
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?
Write a program to convert a decimal number to binary form?
what is runtime class?
Bubble Sort. java thereafter the user will be asked to inpout the size of the list,sort the list in ascending order and display the sorted list in a horizontal manner???
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{
write a program that inputs two real numbers then exchanges their values.
how to create a (*)pyramid using java codes???
is public static void main() work in java?is "String arg[]" needed as argument?
inner join,outerjoin,trigger,stored procedure explain with code snippets?
write a program that will ask the user to enter a number n and display the product of all numbers from 1 to n.