Example : 1
package com.tutorial4u;
package com.tutorial4u;
import java.util.Scanner;
public class Triangle {
public static void main(String[] args) {
int num;
System.out.print("Enter the number of rows : ");
Scanner sc = new Scanner(System.in);
num = sc
.nextInt();
for(int i =1;i<=num;i++){
for(int j =1;j<=i;j++){
System.out.print("*");
}
System.out.println();
}
}
}
Enter
the number of rows : 5
*
**
***
****
*****
Example : 2
Output :
Example : 2
package com.tutorial4u;
import java.util.Scanner;
public class Triangle {
public static void main(String[] args) {
int num;
System.out.print("Enter the number of rows : ");
Scanner sc = new Scanner(System.in);
num = sc
.nextInt();
for(int i =num;i>=1;i--){
for(int j =1;j<=i;j++){
System.out.print("*");
}
System.out.println();
}
}
}
Enter
the number of rows : 7
*******
******
*****
****
***
**
*
Example : 3
Output :
Output :
Example : 5
Output :
Example:6
Output :
package com.tutorial4u;
import java.util.Scanner;
public class Triangle {
public static void main(String[] args) {
int num;
System.out.print("Enter the number of rows : ");
Scanner sc = new Scanner(System.in);
num = sc
.nextInt();
for(int i = num;i>=1;i--){
for(int j =num;j>i;j--){
System.out.print(" ");
}
for(int k=1;k<=i;k++)
{
System.out.print("*");
}
System.out.println();
}
}
}
Enter
the number of rows : 7
*******
******
*****
****
***
**
*
Example : 4
package com.tutorial4u;
import java.util.Scanner;
public class Triangle {
public static void main(String[] args) {
int num;
System.out.print("Enter the number of rows : ");
Scanner sc = new Scanner(System.in);
num = sc
.nextInt();
for(int i = num;i>=1;i--){
for(int j =1;j<i;j++){
System.out.print(" ");
}
for(int k=num;k>=i;k--)
{
System.out.print("*");
}
System.out.println();
}
}
}
Enter
the number of rows : 8
*
**
***
****
*****
******
*******
package com.tutorial4u;
import java.util.Scanner;
public class Triangle {
public static void main(String[] args) {
int num;
System.out.print("Enter the number of rows : ");
Scanner sc = new Scanner(System.in);
num = sc .nextInt();
{
for(int i=1; i<=num; i++)
{
for(int j=num-1; j>=i; j--)
{
System.out.print(" ");
}
for(int k=1; k<=(2*i-1); k++)
{
System.out.print("*");
}
System.out.println("");
}
}
}
}
Enter the number of rows : 5
*
***
*****
*******
*********
Example:6
package com.tutorial4u;
import java.util.Scanner;
public class Triangle {
public static void main(String[] args) {
int num;
System.out.print("Enter the number of rows : ");
Scanner sc = new Scanner(System.in);
num = sc .nextInt();
{
for(int i=num;i>=1;i--)
{
for(int j = num ; j>i;j--)
{
System.out.print(" ");
}
for(int k=1;k<(i*2);k++)
{
System.out.print("*");
}
System.out.println();
}
}
}
}
Enter the number of rows : 7
*************
***********
*********
*******
*****
***
*
No comments:
Post a Comment