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

Introduction To Programming (Programs)

The document contains multiple Java programs that perform various tasks such as calculating simple interest, finding the area of a rectangle, checking if a number is even or odd, determining if a number is a multiple of 5, grading based on input marks, and checking if a number is positive, negative, or zero. Each program includes user input and outputs the result based on specific conditions. The solutions demonstrate basic programming concepts and control structures in Java.
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)
2 views4 pages

Introduction To Programming (Programs)

The document contains multiple Java programs that perform various tasks such as calculating simple interest, finding the area of a rectangle, checking if a number is even or odd, determining if a number is a multiple of 5, grading based on input marks, and checking if a number is positive, negative, or zero. Each program includes user input and outputs the result based on specific conditions. The solutions demonstrate basic programming concepts and control structures in Java.
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

Question:1

Write a program to input Principal, Rate, and Time, and calculate the Simple Interest.
Formula: SI = (P * R * T) / 100

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 of interest: ");
double r = [Link]();
[Link]("Enter Time (in years): ");
double t = [Link]();

double si = (p * r * t) / 100;
[Link]("Simple Interest = " + si);
}
}

Question:2
Write a program to find the area of a rectangle using user input.
Formula: Area = length * breadth

Solution:

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

double area = l * b;
[Link]("Area of Rectangle = " + area);
}
}

---

Question:3
Write a program to check whether a number is even or odd.

Solution:

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

if(num % 2 == 0)
[Link]("Even number");
else
[Link]("Odd number");
}
}

Question:4
Write a program to check whether a number is a multiple of 5.

Solution:

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

if(num % 5 == 0)
[Link]("It is a multiple of 5");
else
[Link]("Not a multiple of 5");
}
}

Question:5
Write a program to input marks (0–100) and print the grade:

90–100 → A

75–89 → B

50–74 → C

35–49 → D

below 35 → Fail

Solution:

import [Link];
class Grade {
public static void main(String args[]) {
Scanner sc = new Scanner([Link]);
[Link]("Enter percentage: ");
int marks = [Link]();

if(marks >= 90 && marks <= 100)


[Link]("Grade: A");
else if(marks >= 75)
[Link]("Grade: B");
else if(marks >= 50)
[Link]("Grade: C");
else if(marks >= 35)
[Link]("Grade: D");
else
[Link]("Grade: Fail");
}
}

Question:6
Write a program to check whether a number is positive, negative, or zero.
Solution:

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

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

You might also like