Computer Applications

Write a program that will read the value of x and compute the following function:

Java

Java Conditional Stmts

3 Likes

Answer

import java.util.Scanner;

public class KboatFunction
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter x: ");
        int x = in.nextInt();
        int y = -1;
        if (x > 0)
            y = 7;
        else if (x == 0)
            y = 0;
        else
            y = -7;
            
        System.out.println("y=" + y);
    }
}

Output

Answered By

1 Like


Related Questions