Last active
December 19, 2015 22:39
-
-
Save shikajiro/6028975 to your computer and use it in GitHub Desktop.
メソッドを作ってみる
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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