7.2.. Napisati program koji za x>y umanjuje vrijednosti obe varijable ( x = x - 2; y = y - 2,) inaæe uveæava vrijednosti obe varijable x = x + 2;
y = y + 2.
a) x = 2, y = 3 b) x = 3, y = 2 c) x = 2, y = 2
d) x = -2, y = -3 e) x = -3, y = 2 f) x = -1, y = -1
Listing programa:
package zadatak;
import java.util.Scanner;
public class P07211031 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Unesi broj x: ");
int x = input.nextInt();
System.out.print("Unesi broj y: ");
int y = input.nextInt();
if (x > y) {
x = x - 2;
y = y - 2;
} else {
x = x + 2;
y = y + 2;
}
System.out.print("x=" + x + ", y=" + y);
}
}
Ispis na ekranu:
Index
|
|