先程も質問させていただいたJavaの初心者で自己紹介プログラムを書いているものです。先ほど質問させていただいたプログラムをメソッドをもちいて完結にしようとしたのですが、タイトルの通り式の開始が不正です。というエラー文が出てしまいます。このエラー分についていろいろと調べてみたのですがそれぞれで言ってる内容が違い初心者の私には何が正解かわかりませんでした。
Java
1コード 2class DateOfBirth { 3 4 int birth_year; 5 int birth_month; 6 int birth_date; 7 boolean known; 8 9} 10class Myfriend { 11 12 String name; 13 DateOfBirth the_date_of_birth; 14 String phone_number; 15 16} 17class Person { 18 String name; 19 20 DateOfBirth the_date_of_birth; 21 String phone_number; 22 int n_of_friends; 23 Myfriend[] friend; 24 25} 26 27class ex6_2 { 28 public static void main(String args[]) { 29 Person person_one; 30 Person person_two; 31 person_one = new Person(); 32 person_two = new Person(); 33 34 /* for protection of personal data, pseudo values are used */ 35 person_one.name = "A"; 36 person_one.the_date_of_birth = new DateOfBirth(); 37 person_one.the_date_of_birth.known = true; 38 Birth birth_year1=new Birth(); 39 40 birth_year1.birthday(2004,3,3); 41 42 43 person_one.phone_number = "080-1234-5678"; 44 45 person_two.name = "Adolf Brain Charles David Frederic John"; 46 person_two.the_date_of_birth = new DateOfBirth(); 47 person_two.the_date_of_birth.known = true; 48 Birth birth_year2=new Birth(); 49 birth_year2.birthday(2004,1,23); 50 person_two.phone_number = "090-8765-4321"; 51 52 /* person_one believes that the 'person_two' is a friend */ 53 person_one.n_of_friends = 1; 54 person_one.friend = new Myfriend[1]; 55 person_one.friend[0] = new Myfriend(); 56 person_one.friend[0].name = person_two.name; 57 person_one.friend[0].the_date_of_birth = new DateOfBirth(); 58 person_one.friend[0].the_date_of_birth.birth_year 59 = person_two.the_date_of_birth.birth_year; 60 person_one.friend[0].the_date_of_birth.birth_month 61 = person_two.the_date_of_birth.birth_month; 62 person_one.friend[0].the_date_of_birth.birth_date 63 = person_two.the_date_of_birth.birth_date; 64 person_one.friend[0].the_date_of_birth.known 65 = person_two.the_date_of_birth.known; 66 person_one.friend[0].phone_number = person_two.phone_number; 67 68 /* however, person_two does not think so. */ 69 person_two.n_of_friends = 0; 70 71 /* print the input data */ 72 print_personal_info(person_one); 73 print_personal_info(person_two); 74 } 75 static void print_personal_info(Person p) { 76 int i; 77 78 System.out.print("NAME: " + p.name + "\n"); 79 80 System.out.print("Number of friends = " + p.n_of_friends + "\n"); 81 for( i = 0; i < p.n_of_friends; i++ ) { 82 System.out.print("Name of friend " + i 83 + ": " + p.friend[i].name + "\n"); 84 if( p.friend[i].the_date_of_birth.known == true ) { 85 System.out.print("Date of Birth: " 86 + p.friend[i].the_date_of_birth.birth_year 87 + " " 88 + p.friend[i].the_date_of_birth.birth_month 89 + " " 90 + p.friend[i].the_date_of_birth.birth_date 91 + "\n"); 92 } else { 93 System.out.print(" Date of birth is unknown.\n"); 94 } 95} 96 static void birthday(int year,int month,int day){ 97 System.out.print("Date of Birth: " + this.year 98 + " " + this.month 99 + " " + this.day + "\n"); 100} 101 102 103 104 105} 106 107
(実行結果)
ex6_2.java:96: エラー: 式の開始が不正です
static void birthday(int year,int month,int day){
^
エラー1個
このようになってしまいます。public ,privateなどいろいろと試したのですが結局なにが悪いのかがわかりませんでした。回答および意見をいただけると幸いです。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/11/08 06:05
2018/11/08 06:08
2018/11/08 06:09
2018/11/08 06:16
2018/11/08 06:17
2018/11/08 06:25
2018/11/08 06:27