Computer Applications
Write a program that will read the value of x and compute the following function:
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
Related Questions
Employees at Arkenstone Consulting earn the basic hourly wage of Rs.500. In addition to this, they also receive a commission on the sales they generate while tending the counter. The commission given to them is calculated according to the following table:
Total Sales Commmision Rate Rs. 100 to less than Rs. 1000 1% Rs. 1000 to less than Rs. 10000 2% Rs. 10000 to less than Rs. 25000 3% Rs. 25000 and above 3.5% Write a program in Java that inputs the number of hours worked and the total sales. Compute the wages of the employees.
Using the switch statement in Java, write a program to display the name of the city according to the user's choice.
D — Delhi, M — Mumbai, K — Kolkata, C — ChennaiAdmission in a professional course is subject to the following criteria:
- Marks in Physics >= 70
- Marks in Chemistry >= 60
- Marks in Mathematics >= 70
- Total marks in all subjects >= 225
Or
Total marks in Physics and Mathematics >= 150
Write a program in Java to accept marks in these 3 subjects (Physics, Chemistry, and Mathematics) and display if a candidate is eligible.