ICSE Class 10 Computer Applications
Question 25 of 43
Conditional Constructs in Java — Question 25
Back to all questions 25
Question Question 25
Write a program that will read the value of x and compute the following function:
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
