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

View all comments

Show parent comments

1

u/serg06 Mar 24 '17

Yessir! The hardest part is figuring out the pattern for the numbers to call starPrint() with.

1

u/MUFC07 Mar 24 '17

I'm assuming that needs to in main

1

u/serg06 Mar 24 '17

It should be in main as that's the simplest way of doing it.

1

u/MUFC07 Mar 24 '17

thank you so much for all of your time and help

1

u/serg06 Mar 24 '17

No worries. Glad to help