answersLogoWhite

0


Best Answer

/**

* Prints a pyramid of asterisks of the specified height.

*

* Will print in the form: printStars(3) =

*

***

*****

*/

public static final void printStars(final int height) {

// perform calculations once

final int totalLength = (height * 2) - 1;

final int totalLength_2 = totalLength / 2;

StringBuilder str = new StringBuilder(totalLength);

// fill with spaces

for (int i = 0; i < totalLength; ++i) {

str.append(' ');

}

// fill in levels

for (int i = 0; i <= totalLength_2; ++i) {

str.setCharAt(totalLength_2 + i, '*');

str.setCharAt(totalLength_2 - i, '*');

System.out.println(str);

}

}

/**

* Prints a pyramid of asterisks of the specified height.

*

* Will print in the form: printStars(3) =

*

* *

* *

*/

public static final void printStars(final int height) {

// perform calculations once

final int totalLength = (height * 2) - 1;

final int totalLength_2 = totalLength / 2;

StringBuilder str = new StringBuilder(totalLength);

// fill with spaces

for (int i = 0; i < totalLength; ++i) {

str.append(' ');

}

// fill in levels

for (int i = 0; i <= totalLength_2; ++i) {

if ((totalLength_2 + i - 1) >= 0) {

str.setCharAt(totalLength_2 + i - 1, ' ');

}

if ((totalLength_2 - i + 1) < totalLength) {

str.setCharAt(totalLength_2 - i + 1, ' ');

}

str.setCharAt(totalLength_2 + i, '*');

str.setCharAt(totalLength_2 - i, '*');

System.out.println(str);

}

} OR second method and easier package javaapplication12; /**

*

* @author Dexy86

*/

public class Main {

public static void main(String[] args) {

for(int i=0; i<5; i++){

for(int v=0;v<i; v++){

System.out.print("*");

}

System.out.println();

}

}

}

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

13y ago

//program to display to trangle of stars.

class Startrangle

{

public static void main(String args[])

{

String str="*",space="";

int i,j;

int imax,jmax;

imax=jmax=20; // you can change this value for maximize you trangle(these are number of steps of trangle)

for(i=1;i<=imax;i++)

{

for(j=jmax;j>=1;j--)

{

space=space.concat(" ");

}

System.out.println(space+str);

str=str.concat("**");

jmax--;

space="";

}

}

}

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

Source Code ::

import java.io.*;
class DiamondStar
{
protected static void main(String args[])throws IOException
{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the limit");
int a=Integer.parseInt(in.readLine()),b,c,d,e,f,g,h=--a;
for(b=0;b<=a;b++)
{
System.out.println();
for(c=a;c>b;c--)
{
System.out.print(" ");
}
for(d=0;d<=b;d++)
{
System.out.print("* ");
}
}
for(e=0;e{
System.out.println();
for(f=0;f<=e;f++)
{
System.out.print(" ");
}
for(g=f;g<=h;g++)
{
System.out.print("* ");
}
}
}
}

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

import java.io.*;

class DiamondStar

{

protected static void main(String args[])throws IOException

{

BufferedReader in=new BufferedReader(new InputStreamReader(System.in));

System.out.println("Enter the limit");

int a=Integer.parseInt(in.readLine()),b,c,d,e,f,g;

--a;

for(b=0;b<=a;b++)

{

System.out.println();

for(c=a;c>b;c--)

{

System.out.print(" ");

}

for(d=0;d<=b;d++)

{

System.out.print("* ");

}

}

for(e=0;e<a;e++)

{

System.out.println();

for(f=0;f<=e;f++)

{

System.out.print(" ");

}

for(g=f;g<=a;g++)

{

System.out.print("* ");

}

}

}

}

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

//By Jithin

import java.util.Scanner;

public class Squre {

int i,j,nstar,ndig;

public Squre(){

i=0;

j=0;

nstar=0;

ndig=0;

}

void display(Squre s){

int k=1;

for(i=0;i<s.nstar;i++){

System.out.print("*");

for(j=1;j<s.nstar-1;j++){

if((i>0)&&(i<s.nstar-1)){

System.out.print(" ");

}

else{

System.out.print("*");

}

}

System.out.print("*");

System.out.println();

}

}

public static void main(String args[]){

Scanner sc=new Scanner(System.in);

Squre s=new Squre();

System.out.println("Enter the number of stars int the squares");

s.nstar=sc.nextInt();

s.display(s);

}

}

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

// diamond shape asterisks

int sp=4; // for spaces

for(int r = 1; r <= 9; r += 2)

{

for(int i = 1; i <= sp ; i++)

System.out.print(" ");

for(int c= 1; c <= r; c++)

{

System.out.print("*");

}

System.out.println();

--sp;

}

int space = 1;

for(int r = 7; r >= 1; r -= 2)

{

for(int i = 1;i <= space; i++)

System.out.print(" ");

for(int c =1;c <= r; c++)

System.out.print("*");

System.out.println();

space++;

}

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

first draw a pyramid and put stars on that simple ho gaya:p

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

This one is the simplest way to Print it :

class Printer {

public static void main(String [] divyansh){

System.out.println("*A*");

}

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you write a simple JAVA program to print the letter A in asterisks?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

You want to write a simple without using pointer or array c program which will print greatest number when you give 20 number?

i want to write a simple without using pointer or array c program which will print greatest number when i give 20 number .........How far have you gotten so far?


Write a unix program to print print a pattern?

echo 'print a pattern'


Write a program that read phrase and print the number of lower-case letter in it using function of counting?

write a program that reads a phrase and prints the number of lowercase latters in it using a function for counting? in C program


How do you write main menu pseudo code?

==== '----------------------------------------------- '*** PROGRAM: Main Menu ' LANGUAGE: QBASIC: VERSION: QB64 '----------------------------------------------- '------------------------------------------ '*** Global variable declarations list... '------------------------------------------ userKeyPress$="" '----------------------- '*** Main Program... '----------------------- DO 'this is a menu driven program... GOSUB clearScreen GOSUB printMainMenuTitleHeading GOSUB printMainMenuOptionsList GOSUB printMainMenuInstructionsHeading GOSUB printMainMenuUserInstructions GOSUB awaitUserKeyPress GOSUB checkUserKeyPress LOOP UNTIL UCASE$(userKeyPress$) = "Q" '...UCASE converts lower case to upper END '...END of program/halt program code execution '---------------------- '*** Sub-routines... '---------------------- clearScreen: CLS '...(CL)ear the output (S)creen RETURN printMainMenuTitleHeading: PRINT "MAIN MENU" PRINT "========" RETURN printMainMenuOptionsList: PRINT "Hit key: &lt;1&gt; for Program 1: 12 X Tables Square" PRINT "Hit key: &lt;2&gt; for Program 2: Select a times tables to print out" PRINT PRINT "Hit key: &lt;Q&gt; to Quit!" PRINT RETURN printMainMenuInstructionsHeading: PRINT "USER INSTRUCTIONS" PRINT "==============" RETURN printMainMenuUserInstructions: PRINT "In order to select from the above Main Menu options list..." PRINT PRINT "First, chose the type of program you wish to run..." PRINT "by, carefully, reading it's description." PRINT PRINT "Then, hit a corresponding single number/letter key, either: '1'/'2';" PRINT "or, alternatively, hit key: 'Q' to Quit!" PRINT PRINT "-Thank you!" RETURN awaitUserKeyPress: DO '...keep looping until when user presses any key... userKeyPress$ = INKEY$ '...store any IN-coming KEY press LOOP UNTIL userKeyPress$ &lt;&gt; "" RETURN checkUserKeyPress: IF userKeyPress$ = "1" THEN GOSUB program1 '...GO to named SUB-routine IF userKeyPress$ = "2" THEN GOSUB program2 '...GO to named SUB-routine RETURN program1: GOSUB clearScreen PRINT "PROGRAM 1" '(...program 1/code goes here...) GOSUB awaitUserKeyPress RETURN program2: GOSUB clearScreen PRINT "PROGRAM 2" '(...program 2/code goes here...) GOSUB awaitUserKeyPress RETURN


Write a java script program to print first ten odd natural numbers in C?

Q.1 Write a program to print first ten odd natural numbers. Q.2 Write a program to input a number. Print their table. Q.3 Write a function to print a factorial value.

Related questions

Write a program to print whether the letter is vowel or not in BASIC?

vowels$ = "aeiou" CLS PRINT "PROGRAM: Find if letter is a vowel or not" PRINT INPUT "Type a single alphabet letter: (a-z)/and, then, press Enter key"; aLetter$ PRINT PRINT "Letter "; aLetter$; IF INSTR(vowels$, LCASE$(aLetter$)) THEN PRINT " is a vowel." ELSE PRINT " is NOT a vowel." END


How do you write the pseudo code for a program that print initials?

Example: start ask the name for each word . print first letter stop


You want to write a simple without using pointer or array c program which will print greatest number when you give 20 number?

i want to write a simple without using pointer or array c program which will print greatest number when i give 20 number .........How far have you gotten so far?


Write a unix program to print print a pattern?

echo 'print a pattern'


Write an assembly language program to print a to z on screen?

write a program to print A to Z on screen in c?


Which is a program embedded in firmware that manages print jobs?

Print Server


How can one print out Christmas cards?

To print out Christmas card is simple. You need cardstock and a printer attached to your computer. You can create cards of your own with a Word or card program you may have installed on your computer or go to a website such as Ecards.


How do you print a booklet?

print it how you normally would and then staple it together.. simple


Write a program that read phrase and print the number of lower-case letter in it using function of counting?

write a program that reads a phrase and prints the number of lowercase latters in it using a function for counting? in C program


How do you print from compaq laptop?

Use the option File / Print in the program you are using.


How do you write main menu pseudo code?

==== '----------------------------------------------- '*** PROGRAM: Main Menu ' LANGUAGE: QBASIC: VERSION: QB64 '----------------------------------------------- '------------------------------------------ '*** Global variable declarations list... '------------------------------------------ userKeyPress$="" '----------------------- '*** Main Program... '----------------------- DO 'this is a menu driven program... GOSUB clearScreen GOSUB printMainMenuTitleHeading GOSUB printMainMenuOptionsList GOSUB printMainMenuInstructionsHeading GOSUB printMainMenuUserInstructions GOSUB awaitUserKeyPress GOSUB checkUserKeyPress LOOP UNTIL UCASE$(userKeyPress$) = "Q" '...UCASE converts lower case to upper END '...END of program/halt program code execution '---------------------- '*** Sub-routines... '---------------------- clearScreen: CLS '...(CL)ear the output (S)creen RETURN printMainMenuTitleHeading: PRINT "MAIN MENU" PRINT "========" RETURN printMainMenuOptionsList: PRINT "Hit key: &lt;1&gt; for Program 1: 12 X Tables Square" PRINT "Hit key: &lt;2&gt; for Program 2: Select a times tables to print out" PRINT PRINT "Hit key: &lt;Q&gt; to Quit!" PRINT RETURN printMainMenuInstructionsHeading: PRINT "USER INSTRUCTIONS" PRINT "==============" RETURN printMainMenuUserInstructions: PRINT "In order to select from the above Main Menu options list..." PRINT PRINT "First, chose the type of program you wish to run..." PRINT "by, carefully, reading it's description." PRINT PRINT "Then, hit a corresponding single number/letter key, either: '1'/'2';" PRINT "or, alternatively, hit key: 'Q' to Quit!" PRINT PRINT "-Thank you!" RETURN awaitUserKeyPress: DO '...keep looping until when user presses any key... userKeyPress$ = INKEY$ '...store any IN-coming KEY press LOOP UNTIL userKeyPress$ &lt;&gt; "" RETURN checkUserKeyPress: IF userKeyPress$ = "1" THEN GOSUB program1 '...GO to named SUB-routine IF userKeyPress$ = "2" THEN GOSUB program2 '...GO to named SUB-routine RETURN program1: GOSUB clearScreen PRINT "PROGRAM 1" '(...program 1/code goes here...) GOSUB awaitUserKeyPress RETURN program2: GOSUB clearScreen PRINT "PROGRAM 2" '(...program 2/code goes here...) GOSUB awaitUserKeyPress RETURN


How to print a jet airways ticket?

If your screen does not give you an option to Print then save the document to a word program and print from there.