質問編集履歴

2

文法の修正

2021/03/10 04:47

投稿

Gingerale09
Gingerale09

スコア8

test CHANGED
File without changes
test CHANGED
@@ -102,10 +102,52 @@
102
102
 
103
103
  public static void main(String[] args) {
104
104
 
105
+ int result = 0;
106
+
105
107
 
106
108
 
107
109
  System.out.println("Here is the result: ");
108
110
 
111
+ int [] multiplyArray = new int [result];
112
+
113
+ int [] valuesArray = new int [result];
114
+
115
+
116
+
117
+ addValues(valuesArray);
118
+
119
+
120
+
121
+ multiplyArray(valuesArray, multiplyArray);
122
+
123
+ System.out.println(Arrays.toString(multiplyArray));
124
+
125
+
126
+
127
+ }
128
+
129
+ }
130
+
131
+
132
+
109
133
 
110
134
 
111
135
  ```
136
+
137
+ エラーメッセージ
138
+
139
+ ```
140
+
141
+ error: cannot find symbol
142
+
143
+ int numVals = findVal();
144
+
145
+ symbol: method findVal()
146
+
147
+ location: class Multiply
148
+
149
+ 1 error
150
+
151
+
152
+
153
+ ```

1

文法の修正

2021/03/10 04:46

投稿

Gingerale09
Gingerale09

スコア8

test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,6 @@
1
1
  ### 前提・実現したいこと
2
+
3
+ 今、配列とメゾットを勉強しています。
2
4
 
3
5
  ユーザーが入力した数字を逆から掛けていくシステムを作りたいです。
4
6
 
@@ -26,19 +28,15 @@
26
28
 
27
29
 
28
30
 
29
- public static void main(String[] args) {
31
+ public static int main() {
30
32
 
31
33
 
32
34
 
33
- //1. ask for how many numbers
35
+ //1. ask for how many numbers
34
36
 
35
- //2.input those numbers into arrays
36
37
 
37
- //3. multiply them
38
38
 
39
- //4.print them out
40
-
41
- Scanner input = new Scanner(System.in);
39
+ Scanner in = new Scanner(System.in);
42
40
 
43
41
  System.out.println("How many numbers?");
44
42
 
@@ -46,64 +44,68 @@
46
44
 
47
45
  int[] array = new int[i];
48
46
 
49
- fill(array, input);
50
-
51
-
52
-
53
- int[] product = pro(array);
54
-
55
-
56
-
57
- System.out.println("The number are ");
58
-
59
- print(product);
47
+ return 0;
60
-
61
-
62
-
63
- }//end main
64
-
65
-
66
-
67
- static void print(int[] numbers) {
68
-
69
- for (int j = 0; j < numbers.length - 1; j++) {
70
-
71
- System.out.print(numbers[j] + " ");
72
-
73
- }
74
-
75
- }//end print
76
-
77
-
78
-
79
- static void fill(int[] numbers, Scanner input) {
80
-
81
- for (int k = 0; k < numbers.length; k++) {
82
-
83
- numbers[k] = input.nextInt();
84
-
85
- }
86
-
87
-
88
-
89
- }//end of fill
90
-
91
-
92
-
93
- private static int[] pro(int[] array) {
94
-
95
- int[] product = new int[List.length];
96
48
 
97
49
  }
98
50
 
99
51
 
100
52
 
101
- ```
53
+ //2.input those numbers into arrays
102
54
 
103
55
 
104
56
 
57
+ public static int addValues(int[] arr) {
58
+
59
+ Scanner in = new Scanner(System.in);
60
+
61
+ for (int i = 0; i < arr.length; i++) {
62
+
63
+ System.out.println("enter number " + (i + 1));
64
+
65
+ arr[i] = in.nextInt();
66
+
67
+ }
68
+
105
- ### 試したこと
69
+ return 0;
70
+
71
+ }
72
+
73
+ //3. multiply them
106
74
 
107
75
 
108
76
 
77
+ public static void multiplyArray(int[] nums, int[] multiply) {
78
+
79
+ int total;
80
+
81
+ for (int i = 0; i < nums.length; i++) {
82
+
83
+ total = 1;
84
+
85
+ for (int j = nums.length; j > i; j--) {
86
+
87
+ total *= nums[(j - 1)];
88
+
89
+ }
90
+
109
- 数字をきくこと以外やり方に自信がないです。
91
+ multiply[i] = total;
92
+
93
+
94
+
95
+ }
96
+
97
+ }
98
+
99
+ //4.print them out
100
+
101
+
102
+
103
+ public static void main(String[] args) {
104
+
105
+
106
+
107
+ System.out.println("Here is the result: ");
108
+
109
+
110
+
111
+ ```