
hi.write a program that will prompt the user for a positive integer(num) and then display two triangles with num number of lines to represent the following patterns of asterisks. the input num must be validated, and if invalid, the user must be allowed a maximum of 3 tries to enter the correct value.
e.g if the user enters 2,the program must display the following patterns:
*
**
**
*

import java.util.*;
class Triangle
{
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
System.out.print("Enter positive number: ");
int num=input.nextInt();
for(int i=1;i<=num;i++){
for(int j=1;j<=i;j++){
System.out.print("*");
}
System.out.println();
}
for(int i=num;i>=1;i--){
for(int j=1;j<=i;j++){
System.out.print("*");
}
System.out.println();
}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.