SRV
Class IX ICSE – Operators in JAVA
Program 1:
Write a program to find and display the value of the given expressions:
a) (x+3)/6 – (2x+5)/3; taking the value of x=5
b) (a^2 + b^2 + c^2)/abc; taking the values a=5,b=4,c=3
public class ArithExp{
public static void main(String args[]){
int x = 5;
int val = (x+3)/6 – (2*x+5)/3;
System.out.println(“Value = ”+ val);
int a=5,b=4,c=3;
float sol = (a*a + b*b + c*c)/(a*b*c);
System.out.println(“Solution = ”+ sol);
}
}
Program 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
public class SalaryCalculator{
public static void main(String args[]){
int payment = 350;
int fine = 30;
int salary=payment*25 + fine*5 ;
System.out.println("The persons salary is = Rs."+ salary); }
}
Program 3:
In a competitive examination, there were 150 questions. One candidate got 80%
correct and the other candidate 72% correct. Write a program to calculate and
display the correct answers each candidate got.
public class CExam{
public static void main(String args[]){
int totalQues = 150;
int c1 = 80/100* totalQues;
int c2 = 72/100* totalQues;
System.out.println("Candidate 1 got "+c1+" questions right");
System.out.println("Candidate 2 got "+c2+" questions right");
}
}
Program 4:
Write a program to find and display the percentage difference when:
a) a number is updated from 80 to 90
b) a number is updated from 7.5 to 7.2
public class PercentIncrease{
public static void main(String args[]){
int orgNum = 80;
int newNum = 90;
int inc = newNum - orgNum;
double p = inc/(double)orgNum * 100;
System.out.println("Percentage difference from 80 to 90="+p+"%");
}
}
Program 5:
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
public class TempConverter{
public static void main(String args[]){
double tF = 98.6;
double tCel = 5/9*(tF+32);
System.out.print("Temperature in Celsius is"+tCel);
}
}
Program 6:
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°
public class QuadAngles{
public static void main(String args[]){
double r1=3, r2=4, r3=5, r4=6;
double x=360/(double)(r1+r2+r3+r4);
double angle1=r1*x;
double angle2=r2*x;
double angle3=r3*x;
double angle4=r4*x;
System.out.println("Angle 1 = "+angle1);
System.out.println("Angle 2 = "+angle2);
System.out.println("Angle 3 = "+angle3);
System.out.println("Angle 4 = "+angle4);
}
}