[go: up one dir, main page]

0% found this document useful (0 votes)
99 views4 pages

20.04.23 IX A Computer

1. The document provides examples and explanations of Java operators and expressions. It includes questions about operator precedence, post-increment/decrement operators, and if/else conditional statements. 2. The document also provides examples of Java programs to calculate expressions, salary income, percentage difference, temperature conversion, and angles of a quadrilateral. The programs demonstrate how to write code to solve the given problems. 3. The document is intended as a study guide for students to practice Java operators, expressions, and programming concepts through examples and exercises.

Uploaded by

anik das
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
99 views4 pages

20.04.23 IX A Computer

1. The document provides examples and explanations of Java operators and expressions. It includes questions about operator precedence, post-increment/decrement operators, and if/else conditional statements. 2. The document also provides examples of Java programs to calculate expressions, salary income, percentage difference, temperature conversion, and angles of a quadrilateral. The programs demonstrate how to write code to solve the given problems. 3. The document is intended as a study guide for students to practice Java operators, expressions, and programming concepts through examples and exercises.

Uploaded by

anik das
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Sacred Heart School

Std IX A Sub: Computer Date: 20.04.2023


Chapter -4 : Operators

Dear students, write the following work in your copies and try to solve the remaining
questions too.
Q. Write the Java expressions for the following:-

1. s=ut+21at2
Ans: s = u * t + (1 / 2) * a * t * t

2. z=x3+y3−zxy
Ans: z = x * x * x + y * y * y - x * y / z

Q. Answer the following:-


1. If m=5, n=2; what will be the output of m and n after execution?
i. m -= n ii. n = m + m/n
Ans: i. m -= n
->m = m - n
->m = 5 - 2
->m = 3

ii. n = m + m/n
->n = 5 + 5/2
->n = 5 + 2
-> n = 7
2. What will be the output for the following program segment?
int a=0,b=10,c=40;
a = --b + c++ +b;
System.out.println(" a = " + a);
Ans: a = 58
Method:-

a = --b + c++ + b
->a = 9 + 40 + 9
-> a = 58
3. Give the output of the program snippet.
int a = 10, b =12;
if(a>=10)
a++;
else
++b;
System.out.println(" a = " + a + " and b = " +b);
Ans: a = 11 and b = 12
Method:-
The condition if(a>=10) is true so a++ increments a to 11. b remains the same.
4. Rewrite the following using ternary operator.
if(income<=100000)
tax = 0;
else
tax = (0.1*income);
Ans: tax = income <= 100000 ? 0 : (0.1*income);

Q. Unsolved Java Programming:-

1. Write a program to find and display the value of the given expression:

(x + 3) / 6 - (2x + 5) / 3;

taking the value of x = 5

Ans: public class KboatExpression


{
public static void main(String args[]) {
int x = 5;
double value = ((x + 3) / 6.0) - ((2 * x + 5) / 3.0);
System.out.println("Result = " + value);
}
}
2. A person is paid ₹350 for each day he works and fined ₹30 for each day he remains absent.
Write a program to calculate and display his monthly income, if he is present for 25 days and
remains absent for 5 days.

Ans: public class KboatSalary


{
public static void main(String args[])
{
int salary = 25 * 350;
int fine = 5 * 30;
int netSalary = salary - fine;
System.out.println("Monthly Income = " + netSalary);
}
}
3. Write a program to find and display the percentage difference, when a number is updated
from 7.5 to 7.2

Ans: public class KboatPercentIncrease


{
public static void main(String args[])
{
double orgNum = 7.5;
double newNum = 7.2;
double inc = newNum - orgNum;
double p = inc / orgNum * 100;
System.out.println("Percentage Difference = " + p + "%");
}
}

4. The normal temperature of human body is 98.6°F. Write a program to convert the
temperature into degree Celsius and display the output.

Hint: c / 5 = f - 32 / 9

Ans: public class KboatCelsius


{
public static void main(String args[])
{
double f = 98.6;
double c = 5 * (f - 32) / 9.0;
System.out.println("Temperature in Degree Celsius = " + c);
}
}
5.The angles of a quadrilateral are in the ratio 3:4:5:6. Write a program to find and display all of
its angles. [Hint: The sum of angles of a quadrilateral = 360°]
Ans: public class KboatQuadRatio
{
public static void main(String args[])
{
int r1 = 3, r2 = 4, r3 = 5, r4 = 6;
double x = 360 / (double)(r1 + r2 + r3 + r4);
double a = r1 * x;
double b = r2 * x;
double c = r3 * x;
double d = r4 * x;
System.out.println("Angle A = " + a);
System.out.println("Angle B = " + b);
System.out.println("Angle C = " + c);
System.out.println("Angle D = " + d);
}
}

You might also like