7.2.. Napisati program koji za y > x računa x i y prema izrazima: x = x - 1; y = x + 2 inače x = x + 1; y = x - 2.

Listing programa:

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

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		System.out.print("Unesi x i y");
		int x = input.nextInt();
		int y = input.nextInt();
		if (y > x) {
			x = x - 1;
			y = x + 2;
		} else {
			x = x + 1;
			y = x - 2;
		}
		System.out.print("x=" + x);
		System.out.println("y=" + y);
	}
}

Ispis na ekranu:

Index