新Javaの写経をしてます。メソッドの方がテストしやすいと言われたので、メソッドテストしたいです。
maxでエラーが出ます。
新・明解Java入門 | 柴田 望洋 | プログラミング | Kindleストア | Amazon
https://www.amazon.co.jp/%E6%96%B0%E3%83%BB%E6%98%8E%E8%A7%A3Java%E5%85%A5%E9%96%80-%E6%9F%B4%E7%94%B0-%E6%9C%9B%E6%B4%8B-ebook/dp/B01HYSUY92
""
import java.util.Scanner; public class MaxHwaMethod { static int max(int a,int b,int c){ int max = a; if (b > max) max = b; if (c > max) max = c; return max; } public static void main(String[] args) throws Exception { // Your code here! Scanner stdIn = new Scanner(System.in); int[] height = new int[3]; int[] weight = new int[3]; int[] age = new int[3]; for(int i = 0; i < 3;i++){ System.out.print("["+(i + 1) + "]"); System.out.print("身長:"); height[i] = stdIn.nextInt(); System.out.print(" 体重:"); weight[i] = stdIn.nextInt(); System.out.print(" 年齢:"); age[i] = stdIn.nextInt(); } int maxHeight = max(height[0],height[1],height[2]); int maxWeight = max(weight[0],weight[1],weight[2]); int maxAge = max(age[0],age[1],age[2]); System.out.println("身長の最大値は"+maxHeight+"です。"); System.out.println("体重の最大値は"+maxWeight+"です。"); System.out.println("年齢の最大値は"+maxAge+"です。"); } } /* 入力例 172 64 32 168 57 24 181 62 18 出力は181 64 31 */
import static org.hamcrest.CoreMatchers.*; import static org.junit.Assert.*; import org.junit.Test; public class MaxHwaMethodTest { @Test public void test() { assertThat(MaxHwaMethodTest.max(172, 168, 181),is(181)); //maxでエラーが出ます。 } }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/05/22 01:24
2019/05/22 06:53