Skip to content

Instantly share code, notes, and snippets.

@shikajiro
Last active December 19, 2015 22:39
Show Gist options
  • Save shikajiro/6028975 to your computer and use it in GitHub Desktop.
Save shikajiro/6028975 to your computer and use it in GitHub Desktop.
メソッドを作ってみる
public class Methods {
public static void main(String[] args) {
hello("しかじろう");
hello("たなか");
hello("やまだ");
int answer = add(3, 4);
System.out.println("戻り値は" + answer);
}
// 引数は複数渡せる。returnで結果を返せる。
public static int add(int x, int y) {
int answer = x + y;
return answer;
}
// こういうのがメソッド
public static void hello(String name) {
System.out.println("こんにちは");
System.out.println(name + "です");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment