-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample_6_4.java
More file actions
44 lines (33 loc) · 1.21 KB
/
Example_6_4.java
File metadata and controls
44 lines (33 loc) · 1.21 KB
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
package unit_06.Examples.Example_04;
import java.util.Scanner;
public class Example_6_4 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("How many numbers do you need to enter: ");
int[] nums = new int[in.nextInt()];
for (int i = 0; i < nums.length; i++) {
System.out.println("Enter number " + (i + 1) +": ");
nums[i] = in.nextInt();
}
System.out.println("**************\nBefore calling method");
Printer(nums);
toSquare(nums);
System.out.println("**************\nAfter calling method");
Printer(nums);
in.close();
}
private static void toSquare(int[] nums){
System.out.println("************\nMake it to Square...");
for (int i = 0; i < nums.length; i++) {
nums[i] = (int)(Math.pow(nums[i], 2));
System.out.println(nums[i]);
}
System.out.println("**************\nAfter change in method");
Printer(nums);
}
private static void Printer(int[] nums){
for (int i = 0; i < nums.length; i++) {
System.out.print("numbers[" + i + "]= " + nums[i] + "\n");
}
}
}