/*-------------- ex9_2.java メソッドの基本(いろいろ使うよ) ---------------*/ import java.util.Scanner; class ex9_2 { int x, y; public static void main(String[] args) { // main メソッド int x, y, res; double re2; Scanner stdIn = new Scanner(System.in); System.out.print(" x = "); x = stdIn.nextInt(); System.out.print(" y = "); y = stdIn.nextInt(); res = addxy(x,y); // addxyメソッドの呼び出し System.out.printf(" %d + %d = %d\n", x, y, res); res = subxy(x,y); System.out.printf(" %d - %d = %d\n", x, y, res); res = mulxy(x,y); System.out.printf(" %d * %d = %d\n", x, y, res); re2 = divxy(x,y); System.out.printf(" %d / %d = %f\n", x, y, re2); } static int addxy(int a, int b) { // addxyメソッド(足し算をするメソッド) int c; c = a + b; return c; } static int subxy(int a, int b) { // 引き算をするメソッド int c; c = a - b; return c; } static int mulxy(int a, int b) { // 掛け算をするメソッド int c; c = a * b; return c; } static double divxy(int a, int b) { // 割り算をするメソッド double c; c = (double)a / (double)b; return c; } }