[go: up one dir, main page]

0% found this document useful (0 votes)
34 views8 pages

Class VIII OCT-2019 Programs-60 Copies

Java class 8

Uploaded by

sarkarbarnali18
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)
34 views8 pages

Class VIII OCT-2019 Programs-60 Copies

Java class 8

Uploaded by

sarkarbarnali18
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/ 8

Program Class 8 (Up to decision makings)

1. Write a program to initialize two integer variables a and b with 5 and 6


respectively and interchange them. Thus after interchanging a and b will be
6 and 5 respectively.
2. Write a program to display the names of five fruits with a single
System.out.println( ); statement, but in different lines.
3. Write a program using variables to find the profit and profit per cent of a
certain transaction where S.P.= Rs.10000 and C.P.= Rs.7000.
4. Write a program to initialize three int variables a, b and c with 234, 456 and
712 and store the sum of the last digits of the variables into d and display it.
5. Write a program to initialize an int variable a with 76498 and from it extract
the first digit and store it in f and extract the last digit in l and display both
these digits.
6. Write a program to input an integer and check whether it is greater than
100, or less than 100 or equal to 100. (use if-else if statement)
7. Write a program to input the Selling Price and Cost Price of a commodity and
find the Profit or Loss made upon selling the product.
For example,
INPUT:
Enter the Selling Price of the commodity: 456
Enter the Cost Price of the commodity: 400
OUTPUT:
Profit: 56
8. Write a program to check whether a int type number taken as input is a
positive, negative or a zero. (Use if-else if statement)
9. Write a program to check whether a short type number taken as input is an
even number or an odd number.
10. Write a program to accept an int type value as a parameter and print the
square of it, if it is more than 120, otherwise print its cube.
11. Write a program to input 5 real numbers (floating point) and find their
average. If the average is greater than 50 print good, otherwise print bad.
12. Write a program to check whether an int type number (taken as input) is a
multiple of 5 or not.
13. Write a program to check whether an int type number (taken as input) is a
2-digit number or not.
14. Write a program to check whether an int type number (taken as input) is a
3-digit number divisible by three or not.
15. Write a program to input an integer and check whether it is a 2-digit or a 3-
digit number or not. In case it is not a 2-digit or a 3-digit number a relevant
message ("Not 2 or 3 digit-number") should be displayed.
16. Write a program to input 2 integers and check whether both the numbers
are multiples of 7 or not.
17. Write a program to input three integers and check whether all of them are
unique (different) from each other or not.
18. Write a program to pass 2 integer numbers as parameters. If either of the
two numbers is 0, display "invalid entry" and the program should end; if it is
valid entry, divide the larger number with the smaller number and display
the result.
19. Write a program to input an integer and check if the number is four-digit
long or longer, the program should give a message that the number is a
"large number". If it is a two-digit long or shorter, then the computer should

Page 1 of 8 www.esaby.org
provide a message that the number is "too small". Otherwise, print a
message WELL DONE, WE THINK ALIKE.
20. Write a program to input 3 unique integers and print the smallest among
them.
21. Write a program to input 3 unique integers and print the smallest among
them without using the logical operator && (AND).
22. Write a program to accept three integer numbers and check whether all of
them are even numbers or not; if they are, it should print "All are even",
otherwise check whether all three are odd or not, if they are it should print
"All are odd". If none of the above conditions are true, it should print "They
are mixed".
23. Write a program to accept 3 integer numbers and check whether the last
digit of every number is 7 or not. If it is, it should print "The last digit of all
the numbers is 7", otherwise it should print, "The last digit is not 7 for every
number".
24. Write a program to input a year and check whether it is a leap year or not.
25. Write a program to accept three angles of a triangle as parameter and check
whether it can form a triangle or not. If it forms a triangle, check whether it
is an acute-angled, obtuse-angled or right angled triangle.
(Hint: To form a triangle, the sum of the angles should be 180 degrees.
To form an acute angled triangle every angle should be less than 90 degrees.
To form an obtuse angled triangle either of the angle should be more than 90
degrees. To form a right angled triangle either of the angle should be equal to
90 degrees.)
26. Write a program to input the three angles of a triangle and check whether it
forms a triangle or not, if it forms a triangle, check whether it is an
equilateral, isosceles or a scalene triangle.
(Hint: To form a triangle, the sum of the angles should be 180 degrees.
To form an equilateral triangle every angle should be equal.
To form an isosceles triangle any two angles should be equal.
To form a scalene triangle all three angles should be different from each
other.)
27. Write a program to input the three sides of a triangle and check whether it
forms a triangle or not, if it forms a triangle, check whether it is an
equilateral, isosceles or a scalene triangle.
(Hint: To form a triangle, each side should be less the sum of the other two
sides.
To form an equilateral triangle every side should be equal.
To form an isosceles triangle any two sides should be equal.
To form a scalene triangle all three sides should be different from each
other.)
28. Write a program to accept three sides of a triangle as parameter and check
whether it can form a triangle or not. If it forms a triangle, check whether it
is an acute-angled, obtuse-angled or right angled triangle.
(Hint: To form a triangle, each side should be less the sum of the other two
sides.
To form an acute-angled triangle the square of every side should be less than
the sum of
the squares of the other two sides.
To form an obtuse-angled triangle the square of any side should be greater
than the sum
of the squares of the other two sides.
To form a right-angled triangle, the square of any side should be equal to the
sum of the

Page 2 of 8 www.esaby.org
29. Write a program to accept a mark obtained by a student in computer science
and print the grades accordingly:

30. A bike shop hires bikes by the day at different rates throughout the year.
The following table shows how the hire charge varies throughout the year:

The proprietor also gives a discount on the number of days a bike is hired
for. If the hire period is greater than 7 days, then a reduction of 25% is
made. For every bike hired a deposit of rupees 50.00 must be paid. Write a
program to input the season and number of days the bike is required for and
output the hire charge including the deposit.

31. A cloth showroom has announced the following festival discounts on the
purchase of items, based on the total cost of the items purchased:

Write a program to input the total cost and compute and display the amount
to be paid by the customer after availing the discount.

32. An electricity company charges their consumers according to the units


consumed per month according to the given tariff:

In addition to the above, every consumer has to pay Rs.200 as service charge
per month. Write a program to input the amount of units consumed and
calculate the total charges payable (bill) by the consumer.

Page 3 of 8 www.esaby.org
33. A library charges a fine for books returned late. Following are the fines:
First five days : 40 paise per day. Six to ten days : 65 paise per day.
Above ten days : 80 paise per day. Design a program to calculate the fine
assuming that a book is returned n days late.
34. Write a program to find the result of the following functions: F(x)=4×x+y if
x>0 F(x)= 4×x–y if x<0 Both x and y should be of float data type and should
be taken as input.
35. Write a program to input an integer and check whether it is a 5-digit number
or not. If it is, extract the central digit and print it. Example:
INPUT: Enter an integer: 76549
OUTPUT: Central digit: 5
INPUT: Enter an integer: 12976
OUTPUT: Central digit: 9
INPUT: Enter an integer: 126
OUTPUT: Not a 5-digit number
36. Write a program to input an integer and check whether it is a 4-digit number
or not. If it is, find the sum of the first and last digit.
Example
INPUT: Enter an integer: 4765
OUTPUT: Sum of the first and last digit: 9
INPUT: Enter an integer: 7839
OUTPUT: Sum of the first and last digit: 16
INPUT: Enter an integer: 126
OUTPUT: Not a 4-digit number
37. Write a program to input an integer and check whether it is a 3-digit number
or not. If it is check whether the sum of the first and last digit is an even or
an odd number.
Example
INPUT: Enter an integer: 476
OUTPUT: Sum of the first and last digit is an even number
INPUT: Enter an integer: 784OUTPUT: Sum of the first and last digit is an
odd number
INPUT: Enter an integer: 12
OUTPUT: Not a 3-digit number
38. Write a program to input an integer and check whether it is a 4-digit number
or not. If it is, divide it into two equal halves and find their sum.
Example
INPUT: Enter an integer: 4762
OUTPUT: Sum of the 2 halves: 109
[Hint: 47+62=109]
INPUT: Enter an integer: 9863
OUTPUT: Sum of the 2 halves: 161
[Hint: 98+63=161]
INPUT: Enter an integer: 12
OUTPUT: Not a 4-digit number

39. Write a program to find the gross salary of an employee for the following
allowances and deductions. Use meaningful variables with the class name
Employee and Basic Pay as an input.

Page 4 of 8 www.esaby.org
40. To foster a sense of water conservation, the water department has an annual
water conservation tax policy. The taxes are based on the water
consumption of the consumer. The tax rates are as follows:
Write a program to input the water consumed annually in gallons and
output the tax payable.

Page 5 of 8 www.esaby.org
Page 6 of 8 www.esaby.org
Page 7 of 8 www.esaby.org
Page 8 of 8 www.esaby.org

You might also like