7.2. Učitati dva realna broja (a, b), izračunati z prema izrazu:

Opis rješenja:

Listing programa:

package zadatak;
import java.util.Scanner;
public class P07212004 {
	public static void main(String[] args)	{
	Scanner input = new Scanner (System.in);

		System.out.print("Unesi a: ");
		int a=input.nextInt();
		System.out.print("Unesi b: ");
		int b=input.nextInt();
 
		if (a>b)
			System.out.print("2*a+b= " +(2*a+b));
		else
			System.out.print("a-2*b= " +(a-2*b));
}}

II varijanta
package zadatak;
import java.util.Scanner;
public class P07212004 {
	public static void main(String[] args)	{
	Scanner input = new Scanner (System.in);

	    double a, b, z;
		System.out.print("'Brojevi: ");
		int a=input.nextDouble();
		int b=input.nextDouble();

		if (a > b)
			z = 2*a + b;
		else
			z = a - 2*b;
	    System.out.println("a= " + a + "  b = " + b + " z = " + z);
}}

Ispis na ekranu:

Index