7.2.. Učitati dva broja (x i a). Varijabli z pridružiti vrijednost prema slijedećem izrazu:
Opis rješenja:
Listing programa:
package zadatak;
import java.util.Scanner;
public class P07211064 {
public static void main(String[] args) {
Scanner input = new Scanner (System.in);
double x, a;
System.out.print("Ukucajte brojeve x i a: ");
double x=input.nextDouble();
double a=input.nextDouble();
if (x>a)
System.out.print("x/3=" +(x/3));
else
System.out.print("x+3=" +(x+3));
}}
II varijanta
package zadatak;
import java.util.Scanner;
public class P07211064 {
public static void main(String[] args) {
Scanner input = new Scanner (System.in);
double x, a, z;
System.out.print("Ukucajte brojeve x i a: ");
double x=input.nextDouble();
double a=input.nextDouble();
if (x > a)
z = x / 3;
else
z = x + 3;
System.out.println("x= " + x + " a = " + a + " z = " + z);
}}
Ispis na ekranu:
Index
|