Spaces:
Running
Running
File size: 1,491 Bytes
a760458 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
In Java, all subprograms are called methods.
In programming, a method is generally a subprogram bound to a class.
In Java, all subprograms are methods because all program code is always written inside a class.
methods of procedure type, that is, methods that have NO RETURN VALUE.
In this case, we are actually talking about an empty return value - the type of return value is VOID.
public static void methodName(<list of parameters>) {
<method structure>
}
public class Example {
public static void main(String[] args) {
System.out.println("Hello everyone!");
}
}
The main method has a special meaning in Java programs:
if a class has a MAIN METHOD, it is AUTOMATICALLY EXECUTED 1ST when the class is executed.
=================================
1. Write the main method
Write the main method in the program. The method should print a table of six multiples exactly as shown in the example output below.
Output:
Table of six multiples
1 x 6 = 6
2 x 6 = 12
3 x 6 = 18
4 x 6 = 24
5 x 6 = 30
6 x 6 = 36
7 x 6 = 42
8 x 6 = 48
9 x 6 = 54
10 x 6 = 60
import java.util.Random;
public class Test{
public static void main(String[] args){
System.out.println("Table of six multiples");
for (int i = 1; i <= 10; i++) {
System.out.println(i + " x 6 = " + (i * 6));
}
}
}
Table of six multiples
1 x 6 = 6
2 x 6 = 12
3 x 6 = 18
4 x 6 = 24
5 x 6 = 30
6 x 6 = 36
7 x 6 = 42
8 x 6 = 48
9 x 6 = 54
10 x 6 = 60
|