x > 0 : z = 2x^2
x < 0 : z = 2x + 4y
x = 0 : z = 1
public class HW03_08 { public static void main(String[] args) { int z; System.out.print("Input x: "); int x = new java.util.Scanner(System.in).nextInt(); if (x > 0) { z = 2 * (x*x); } else if (x < 0) { System.out.print("Input y: "); int y = new java.util.Scanner(System.in).nextInt(); z = (2 * x) + (4 * y); } else { z = 1; } System.out.println ("z = " + z); } }
ไม่มีความคิดเห็น:
แสดงความคิดเห็น