65 611
Assignments Done
99,2%
Successfully Done
In October 2018

Answer to Question #8741 in Java | JSP | JSF for jennilee

Question #8741
write a java program that wil prompt the user for a positive integer(num)and then display two triagles with num number of line to represent the following pattern 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
Expert's answer
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();
}

}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions