Grade 9 Unsolved Pgms 4 5 6 1728570562
Grade 9 Unsolved Pgms 4 5 6 1728570562
Unsolved Programmes
1)Write a program to find and display the value of the given
expression:
A. (x + 3) / 6 - (2x + 5) / 3;
taking the value of x = 5
public class Expression
{
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);
}
}
B. a2 + b2 + c2 / abc;
taking the values a=5, b=4, c=3
public class Expression
{
public static void main(String args[]) {
int a = 5, b = 4, c = 3;
double value = (a * a + b * b + c * c) / (double)(a * b * c);
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.
public class Salary
{
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) 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 CompetitiveExam
{
public static void main(String args[]) {
int totalQuestions = 150;
int c1 = (int)(80 / 100.0 * totalQuestions);
int c2 = (int)(72 / 100.0 * totalQuestions);
System.out.println("Correct Answers of Candidate 1 = " + c1);
System.out.println("Correct Answers of Candidate 2 = " + c2);
}
}
4) Write a program to find and display the percentage difference,
when a number is updated from 80 to 90
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 = " + p + "%");
}
}
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 Celsius
{
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);
}
}
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 QuadRatio
{
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);
}
}
5. INPUT IN JAVA
1.
import java.util.Scanner;
public class SimplePendulum
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.print("Enter Length: ");
double l = in.nextDouble();
System.out.print("Enter Gravity: ");
double g = in.nextDouble();
double t = 2 * 3.14159 * Math.sqrt(l / g);
System.out.println("Time Period = " + t);
in.close();
}
}
Output
Output
import java.util.Scanner;
5.
import java.util.Scanner;
6
public class Shares
{
public static void main(String args[]) {
int sharesHeld = (2000 * 100)/(10 * 10);
System.out.println("No. of shares held currently = "
+ sharesHeld);
int sharesRequired = 3000 - sharesHeld;
System.out.println("No. of shares to purchase = "
+ sharesRequired);
}
}
Output
7
Write a program to input time in seconds. Display the time after converting
them into hours, minutes and seconds.
Sample Input: Time in seconds: 5420
Sample Output: 1 Hour 30 Minutes 20 Seconds
import java.util.Scanner;
System.out.println(hrs
+ " Hours "
+ mins
+ " Minutes "
+ secs
+ " Seconds");
}
}
Output
8
import java.util.Scanner;
10
import java.util.Scanner;
Question 4
import java.util.Scanner;