A simple program that will ask the user to give a number and then the program will generate the asterisk triangle using Java programming language.
My email address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com
Program Listing
/* Asterisk.java
* Author : Jake Rodriguez Pomperada, MAED-IT, MIT
* April 5, 2021 8:13 PM
* www.jakerpomperada.blogspot.com
* www.jakerpomperada.com
* jakerpomperada@gmail.com
* Bacolod City, Negros Occidental
*/
import java.util.Scanner;
public class Asterisks {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println();
System.out.print("\tAsterisk Triangle in Java");
System.out.println("\n");
System.out.print("\tEnter a number: ");
int number = scan.nextInt();
int res;
System.out.println("\n");
for (int a=1; a<=number; a++) {
System.out.print("\t");
res = number - a;
for (int b=0; b<=res;b++) {
System.out.print("*");
}
System.out.println("");
}
}
}
No comments:
Post a Comment