メソッドについてお伺いしたいです。
下記のプログラムを作りました。
java
1コード 2```import java.util.Scanner; 3 public class Med3 { 4 public static int med(int a, int b, int c){ 5 if((a < b && b < c) ||(c < b && b < a)) { 6 return b; 7 } else if((a < c && c < b) ||(b < c && c < a)) { 8 return c; 9 } else return a; 10 } 11 12 public static void main(String args[]){ 13 System.out.println("数値を入力してください"); 14 Scanner s = new Scanner (System.in); 15 int a = s.nextInt(); 16 int b = s.nextInt(); 17 int c = s.nextInt(); 18 s.close(); 19 System.out.println("中央値は"+ med(a, b, c) + "です。"); 20 } 21} 222行目の「public class Med3 { 」でpublicを付けても付けなくてもエラーにならないのがよく理解できません。理由やメカニズム等を教えていただけるとありがたいです。
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。