7.2.. Napisati program za odredjivanje y po formuli:

Listing programa:

package Zadatak;
import java.util.Scanner;
public class P07211090 {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		System.out.println("Unesi x");
		double y;
		double x = input.nextDouble();
		if (x < -2)
			y = 2 * x;
		else if (x > -2)
			y = 1 - x;
		else
			y = 3 * x + 1;
		System.out.println("y=" + y);
	}
}

Ispis na ekranu:

Index