could you help me to solve it Q; Write a function printStarts(int n). Write a loop from 1 to n and print stars in single line.
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
could you help me to solve it Q; Write a function printStarts(int n). Write a loop from 1 to n and print stars in single line.
What have you tried? Where are you stuck?
Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
Welcome to the forum! Please read this topic to learn how to post code correctly and other useful info for new members.
here's the algorithm+pseudocode that might help you solve this (am just saying, "instruction in plain english")
1) write name of function (must accept an integer as parameter)
2) start a loop using "for"
3) from 1 to "whatever the integer parameter"...loop.... until current count is equal to "whatever the integer parameter"....increment count as you go
4) for every loop....print a star
here's the code.
public void printStars(int numberOfStarsToPrint){ //you might want to validate the parameter here (optional for you) // GB: solution removed } }
@johnbee: please review The Problem with Spoon-feeding.
JosAH (March 1st, 2019)
sorry and thank you.
With the printers they have now or the older versions, I think that an empty class method would do it. Printing it out. In a single line; an if ..then statement is enclosed in a while loop. Use of a System.out.println method. Increment or decrement each counter or variable loop iteration. It comes out like this. 10 9 8 7 6 5 3 2 1
Further posting on old threads may result in banning.
If you don't understand my answer, don't ignore it, ask a question.