- #1
Hiche
- 84
- 0
Okay.
So, I'm taking up a beginning Java course in college and we have been assigned a rather simple (?) homework.
We have to code a program that prints a statement a thousand times, but without the use of loops, only methods. I know I can create a method that contains a number of the statement and then call it several times from the main method, but is there an easier way? Our instructor asked for the simplest way. Is the one I mentioned the simplest way when we are limited to methods?
I'm still new to programming. How did I know about loops? Read a few further chapters ahead of our course.
So, I'm taking up a beginning Java course in college and we have been assigned a rather simple (?) homework.
We have to code a program that prints a statement a thousand times, but without the use of loops, only methods. I know I can create a method that contains a number of the statement and then call it several times from the main method, but is there an easier way? Our instructor asked for the simplest way. Is the one I mentioned the simplest way when we are limited to methods?
I'm still new to programming. How did I know about loops? Read a few further chapters ahead of our course.
Code:
public class MyProgram
{
public static void main(String[] args)
{
printThousandTimes();
printThousandTimes();
// call some more and more..
}
public static void printStatement
{
System.out.println("statement");
}
public static void printThousandTimes
{
printStatement();
printStatement();
printStatement();
printStatement();
printStatement();
printStatement();
printStatement();
printStatement();
printStatement();
printStatement();
}
}