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
1
Expert's answer
2012-04-26T07:31:22-0400
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 the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS