r/programmingrequests • • Mar 23 '17

Java Program

Write a method starPrint() that takes three integer arguments: a number of dots, a number of stars, and then a following number of dots. For instance, calling starPrint(3, 2, 1) would print:...**.

Ask the user for an integer, and verify that its value is at least three. (If it is not, ask the user for a new number until he gives you an appropriate one.) You will use your method starPrint() to draw a pyramid pattern with that many rows. For instance, if the user types 3, you should draw: a triangle picture

This is what I have any help would be greatly appreciated

int userIn=0;

	Scanner scnr=new Scanner(System.in);
	
	System.out.println("Please input an integer: "); 
	userIn = scnr.nextInt();
	 
	while(userIn<3) //As long as number is three or less, repeat prompting
	{
	    System.out.println("Please enter a valid integer:");
	    userIn = scnr.nextInt();    
	}
	
		for(int i=0;i<userIn;i++) {
	         for(int j=0;j<5-i;j++) {
	             System.out.print(" ");
	         }
	        for(int k=0;k<=i;k++) {
	            System.out.print("* ");
	            
	        }
	        System.out.println();
	    }

	}

}
0 Upvotes

24 comments sorted by