質問するログイン新規登録

質問編集履歴

3

1

2019/12/17 03:07

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -1,68 +1,1 @@
1
- ### 前提・実現したいこと
2
- mainメソッドから、getUserProfile()を呼び出して、戻り値の要素をすべて取り出したいのですが
1
+ -----------------------------------------------------
3
- うまくいきません。改善点が見つからなくなり、助言お願いします。
4
- ## 発生している問題・エラーメッセージ
5
-
6
- ```
7
- Main.java:13: error: method getUserProfile in class Main cannot be applied to given types;
8
- System.out.print(getUserProfile(i)+",");
9
- ^
10
- required: no arguments
11
- found: int
12
- reason: actual and formal argument lists differ in length
13
- 1 error
14
-
15
- ### 該当のソースコード
16
-
17
- ```ここに言語名を入力
18
-
19
- public class Main {
20
- static String[] getUserProfile(){
21
- String[] profile ={"1","太郎","東京","男","プログラマー"};
22
-
23
-
24
- return profile;
25
- }
26
-
27
-
28
- public static void main(String[] agrs){
29
- for(int i=0; i<5; i++){
30
- System.out.print(getUserProfile(i) +",");
31
- }
32
- }
33
-
34
- }
35
- ```
36
-
37
- ### 試したこと
38
- int型をString型に型変換することで解決しました。
39
-
40
- public class Main {
41
- // *変更 getUserProfile(int num)←ここ{
42
- static String[] getUserProfile(int num){
43
- String[] profile0 ={"1","太郎","東京","男","プログラマー"};
44
-
45
- //*追加 int型の引数ををString型に変換
46
- String strnum=String.valueOf(num);
47
-
48
-
49
- return profile0;
50
- }
51
-
52
-
53
- public static void main(String[] agrs){
54
-
55
- //*追加 getUserProfileメソッドからの戻り値を代入
56
- String[] profile=getUserProfile(1);
57
-
58
- //*変更 iの上限を要素数に合わせる
59
- for(int i=0; i<profile.lenth; i++){
60
- System.out.print(profile[i]);
61
- }
62
- }
63
-
64
- }
65
-
66
- ### 補足情報(FW/ツールのバージョンなど)
67
-
68
- ここにより詳細な情報を記載してください。

2

自己解決いたしました。一からメソッドを学びなおし全修正いたしました。 役立てれば幸いです。

2019/12/17 03:07

投稿

退会済みユーザー
title CHANGED
@@ -1,1 +1,1 @@
1
- メソッドからの戻り値の要素をすべて取り出したい
1
+ メソッドからの戻り値の要素を取り出int型からString型に、型変換。
body CHANGED
@@ -35,9 +35,34 @@
35
35
  ```
36
36
 
37
37
  ### 試したこと
38
+ int型をString型に型変換することで解決しました。
38
39
 
39
- ここに問題に対して試したことを記載してください。
40
+ public class Main {
41
+ // *変更 getUserProfile(int num)←ここ{
42
+ static String[] getUserProfile(int num){
43
+ String[] profile0 ={"1","太郎","東京","男","プログラマー"};
40
44
 
45
+ //*追加 int型の引数ををString型に変換
46
+ String strnum=String.valueOf(num);
47
+
48
+
49
+ return profile0;
50
+ }
51
+
52
+
53
+ public static void main(String[] agrs){
54
+
55
+ //*追加 getUserProfileメソッドからの戻り値を代入
56
+ String[] profile=getUserProfile(1);
57
+
58
+ //*変更 iの上限を要素数に合わせる
59
+ for(int i=0; i<profile.lenth; i++){
60
+ System.out.print(profile[i]);
61
+ }
62
+ }
63
+
64
+ }
65
+
41
66
  ### 補足情報(FW/ツールのバージョンなど)
42
67
 
43
68
  ここにより詳細な情報を記載してください。

1

17行目に")"が一つ多いので削除しました。が、また違うエラーになりました。

2019/11/19 02:22

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -4,14 +4,13 @@
4
4
  ## 発生している問題・エラーメッセージ
5
5
 
6
6
  ```
7
- Main.java:17: error: not a statement
7
+ Main.java:13: error: method getUserProfile in class Main cannot be applied to given types;
8
- System.out.print(getUserProfile(i)) +",");
8
+ System.out.print(getUserProfile(i)+",");
9
9
  ^
10
- Main.java:17: error: ';' expected
10
+ required: no arguments
11
+ found: int
11
- System.out.print(getUserProfile(i)) +",");
12
+ reason: actual and formal argument lists differ in length
12
- ^
13
- 2 errors
13
+ 1 error
14
- ```
15
14
 
16
15
  ### 該当のソースコード
17
16
 
@@ -28,7 +27,7 @@
28
27
 
29
28
  public static void main(String[] agrs){
30
29
  for(int i=0; i<5; i++){
31
- System.out.print(getUserProfile(i)) +",");
30
+ System.out.print(getUserProfile(i) +",");
32
31
  }
33
32
  }
34
33