1.program to check the given number is positive ,negative or zero.
Public class NumberCheck {
Public static void main(String[] args) {
Int number = -5;
If (number > 0) {
System.out.println(“The number is positive.”);
} else if (number < 0) {
System.out.println(“The number is negative.”);
} else {
System.out.println(“The number is zero.”);
2.program to list the factorial of the numbers from 1 to 10.
Public class Factorial {
Public static void main(String[] args) {
For (int i = 1; i <= 10; i++) {
Int fact = 1;
For (int j = 1; j <= i; j++) {
Fact *= j;
System.out.println(“Factorial of “ + i + “ is “ + fact);
}
3.demonstrate classes and objects.
class Car {
String brand;
int year;
void displayInfo() {
System.out.println("Brand: " + brand);
System.out.println("Year: " + year);
public class Main {
public static void main(String[] args) {
Car car = new Car();
car.brand = "Tesla";
car.year = 2023;
car.displayInfo();
4. demonstration of method overloading
class Calculator {
int add(int a, int b) {
return a + b;
}
int add(int a, int b, int c) {
return a + b + c;
public class Main {
public static void main(String[] args) {
Calculator calc = new Calculator();
System.out.println(calc.add(5, 10));
System.out.println(calc.add(3, 2, 1));
5.single inheritance.
Class Calculator {
Int add(int a, int b) {
Return a + b;
Int subtract(int a, int b) {
Return a – b;
Class AdvancedCalculator extends Calculator {
Int multiply(int a, int b) {
Return a * b;
Public class Main {
Public static void main(String[] args) {
AdvancedCalculator calc = new AdvancedCalculator();
System.out.println(“Addition: “ + calc.add(5, 3));
System.out.println(“Subtraction: “ + calc.subtract(5, 3));
System.out.println(“Multiplication: “ +calc.multiply(5,3));
6)to find maximum and minimum element in one dimensional array
public class ArrayMinMax {
public static void main(String[] args) {
int[] arr = {3, 5, 7, 2, 8, 1, 9};
int max = arr[0];
int min = arr[0];
for (int i = 1; i < arr.length; i++) {
if (arr[i] > max) {
max = arr[i];
if (arr[i] < min) {
min = arr[i];
}
System.out.println("Maximum element: " + max);
System.out.println("Minimum element: " + min);
7) check the given string is palindrome or not
Public class PalindromeCheck {
Public static void main(String[] args) {
String str = “madam”;
String reversedStr = “”;
For (int i = str.length() – 1; i >= 0; i--) {
reversedStr += str.charAt(i);
If (str.equals(reversedStr)) {
System.out.println(str + “ is a palindrome.”);
} else {
System.out.println(str + “ is not a palindrome.”);
}
8) Program to create a 'Student 'class with Reg. No, name, and marks of 3
subjects, Calculate the total marks of 3. Subject and create an array of 3
student objects of display the results
Class Student {
Int regNo;
String name;
Int marks1, marks2, marks3;
Void displayResults() {
Int total = marks1 + marks2 + marks3;
System.out.println(“Reg. No: “ + regNo + “, Name: “ + name);
System.out.println(“Marks in Subject 1: “ + marks1);
System.out.println(“Marks in Subject 2: “ + marks2);
System.out.println(“Marks in Subject 3: “ + marks3);
System.out.println(“Total Marks: “ + total);
System.out.println();
Public class Main {
Public static void main(String[] args) {
Student[] students = new Student[3];
Students[0] = new Student();
Students[0].regNo = 101;
Students[0].name = “Alice”;
Students[0].marks1 = 85;
Students[0].marks2 = 90;
Students[0].marks3 = 95;
Students[1] = new Student();
Students[1].regNo = 102;
Students[1].name = “Bob”;
Students[1].marks1 = 78;
Students[1].marks2 = 88;
Students[1].marks3 = 92;
Students[2] = new Student();
Students[2].regNo = 103;
Students[2].name = “Charlie”;
Students[2].marks1 = 80;
Students[2].marks2 = 85;
Students[2].marks3 = 90;
For (Student student : students) {
Student.displayResults();