/*-------------- ex9_1.java メソッドの基本 ---------------*/ import java.util.Scanner; class ex9_1 { public static void main(String[] args) { // main メソッド int x, y, res; Scanner stdIn = new Scanner(System.in); System.out.println("足し算プログラム[x+y=?]"); System.out.print(" x = "); x = stdIn.nextInt(); System.out.print(" y = "); y = stdIn.nextInt(); res = addxy(x,y); // addxyメソッドの呼び出し System.out.printf(" x + y = %d\n", res); // format指定で表示 System.out.printf(" %2d + %2d = %3d\n", x, y, res); // format指定で表示 System.out.println( x + " + " + y + " = " + res ); // Java の書き方 } static int addxy(int a, int b) { // addxyメソッド int c; c = a + b; return c; } }