0% found this document useful (0 votes)
4 views6 pages

Java Class8 Programming Solutions

Java Class8 Programming Solutions

Uploaded by

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

Java Class8 Programming Solutions

Java Class8 Programming Solutions

Uploaded by

madhubelakoba
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

JAVA PROGRAMMING PROBLEMS

With Complete Solutions · Class 8 · ICSE Board


These are the 8 programming problems from the practice set, each with a problem statement, a sample run, and a complete,
ready-to-run Java solution. Encourage students to attempt each problem on their own in BlueJ before checking the solution.

Problem 1: Sum, Difference, Product, Quotient of Two Numbers


Accept two numbers from the user and display their sum, difference, product, and quotient.
Sample: Input a = 20, b = 4 → Output Sum = 24, Difference = 16, Product = 80, Quotient = 5.0
Solution:

import [Link];

class Arithmetic
{
public static void main(String args[])
{
Scanner sc = new Scanner([Link]);
[Link]("Enter first number: ");
double a = [Link]();
[Link]("Enter second number: ");
double b = [Link]();

[Link]("Sum = " + (a + b));


[Link]("Difference = " + (a - b));
[Link]("Product = " + (a * b));
[Link]("Quotient = " + (a / b));
}
}

Problem 2: Area and Circumference of a Circle


Accept the radius of a circle and calculate its area and circumference. (Use 3.14 for π)
Sample: Input radius = 7 → Output Area = 153.86, Circumference = 43.96
Solution:

import [Link];

class Circle
{
public static void main(String args[])
{
Scanner sc = new Scanner([Link]);
[Link]("Enter radius: ");
double radius = [Link]();

double area = 3.14 * radius * radius;


double circumference = 2 * 3.14 * radius;

[Link]("Area = " + area);


[Link]("Circumference = " + circumference);
}
}
Problem 3: Volume of a Cuboid
Accept the length, breadth, and height of a cuboid and find its volume.
Sample: Input l = 5, b = 3, h = 2 → Output Volume = 30.0
Solution:

import [Link];

class Cuboid
{
public static void main(String args[])
{
Scanner sc = new Scanner([Link]);
[Link]("Enter length: ");
double length = [Link]();
[Link]("Enter breadth: ");
double breadth = [Link]();
[Link]("Enter height: ");
double height = [Link]();

double volume = length * breadth * height;


[Link]("Volume of cuboid = " + volume);
}
}

Problem 4: Total and Percentage of Marks


Accept marks in three subjects and calculate and print the total and percentage (out of 300).
Sample: Input 85, 90, 78 → Output Total = 253, Percentage = 84.33
Solution:

import [Link];

class Percentage
{
public static void main(String args[])
{
Scanner sc = new Scanner([Link]);
[Link]("Enter marks in Subject 1: ");
double m1 = [Link]();
[Link]("Enter marks in Subject 2: ");
double m2 = [Link]();
[Link]("Enter marks in Subject 3: ");
double m3 = [Link]();

double total = m1 + m2 + m3;


double percentage = (total / 300) * 100;

[Link]("Total = " + total);


[Link]("Percentage = " + percentage);
}
}
Problem 5: Positive, Negative, or Zero
Accept a number and print whether it is positive, negative, or zero.
Sample: Input num = -8 → Output Output: -8 is Negative
Solution:

import [Link];

class CheckNumber
{
public static void main(String args[])
{
Scanner sc = new Scanner([Link]);
[Link]("Enter a number: ");
int num = [Link]();

if (num > 0)
[Link](num + " is Positive");
else if (num < 0)
[Link](num + " is Negative");
else
[Link]("The number is Zero");
}
}

Problem 6: Simple Interest


Accept the principal, rate, and time and calculate the Simple Interest using the formula SI = (P × R × T) / 100.
Sample: Input P = 10000, R = 5, T = 2 → Output Simple Interest = 1000.0
Solution:

import [Link];

class SimpleInterest
{
public static void main(String args[])
{
Scanner sc = new Scanner([Link]);
[Link]("Enter Principal: ");
double p = [Link]();
[Link]("Enter Rate: ");
double r = [Link]();
[Link]("Enter Time: ");
double t = [Link]();

double si = (p * r * t) / 100;
[Link]("Simple Interest = " + si);
}
}
Problem 7: Celsius to Fahrenheit Conversion
Accept temperature in Celsius and convert it to Fahrenheit using F = (C × 9/5) + 32.
Sample: Input C = 37 → Output Fahrenheit = 98.6
Solution:

import [Link];

class TemperatureConverter
{
public static void main(String args[])
{
Scanner sc = new Scanner([Link]);
[Link]("Enter temperature in Celsius: ");
double celsius = [Link]();

double fahrenheit = (celsius * 9.0 / 5.0) + 32;


[Link]("Temperature in Fahrenheit = " + fahrenheit);
}
}

Problem 8: Years Left to Turn 18


Accept a student's name and age, then display a message in the format: "<name> will turn 18 in <n> years."
Sample: Input name = Riya, age = 13 → Output Output: Riya will turn 18 in 5 years.
Solution:

import [Link];

class YearsToAdult
{
public static void main(String args[])
{
Scanner sc = new Scanner([Link]);
[Link]("Enter name: ");
String name = [Link]();
[Link]("Enter age: ");
int age = [Link]();

int yearsLeft = 18 - age;


[Link](name + " will turn 18 in " + yearsLeft + " years.");
}
}

Tip for students: type these programs yourself in BlueJ instead of copy-pasting — it builds muscle memory for Java syntax.

You might also like