0% found this document useful (0 votes)
8 views13 pages

OOPS With Java Lab

The document contains a series of Java programming assignments focused on Object-Oriented Programming (OOP) concepts. Each assignment includes a specific task, such as addition, swapping numbers, checking for prime numbers, and implementing classes with constructors. The document serves as a lab report submitted by a student, detailing their solutions to these programming exercises.

Uploaded by

arunnegi9625
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)
8 views13 pages

OOPS With Java Lab

The document contains a series of Java programming assignments focused on Object-Oriented Programming (OOP) concepts. Each assignment includes a specific task, such as addition, swapping numbers, checking for prime numbers, and implementing classes with constructors. The document serves as a lab report submitted by a student, detailing their solutions to these programming exercises.

Uploaded by

arunnegi9625
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

OOPS With Java Lab

(ARI 256)

Submitted to: Dr. Renu Dalal

Submitted by: Arun Singh Negi

01919051724

IIOT B1 2028
Index
S. Pa
Experiment Sign
N. ge
S. Pa
Experiment Sign
N. ge
ASSIGNMENT NO. 1:
Write a program to display the addition result of any two integers.

Program:
public class Addition {

public static void main(String[] args) {

int a = 10;

int b = 20;

int sum = a + b;

[Link]("First number: " + a);

[Link]("Second number: " + b);

[Link]("Sum: " + sum);

}
ASSIGNMENT NO. 2:
Write a program for the swapping of two numbers.

Program:
public class SwapNumbers {

public static void main(String[] args) {

int a = 5;

int b = 10;

[Link]("Before swapping:");

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

int temp = a;

a = b;

b = temp;

[Link]("After swapping:");

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

}
ASSIGNMENT NO. 3:
Write a program to print all the prime numbers between 100 to 200.

Program:
public class PrimeNumbers {

public static void main(String[] args) {

[Link]("Prime numbers between 100 and 200:");

for (int i = 100; i <= 200; i++) {

int count = 0;

for (int j = 1; j <= i; j++) {

if (i % j == 0) {

count++;

if (count == 2) {

[Link](i + " ");

}
ASSIGNMENT NO. 4:
Write a program to check whether a number is palindrome or not.

Program:
import [Link];

public class PalindromeNumber {

public static void main(String[] args) {

Scanner sc = new Scanner([Link]);

[Link]("Enter a number: ");

int num = [Link]();

int original = num;

int reversed = 0;

while (num > 0) {

int digit = num % 10;

reversed = reversed * 10 + digit;

num = num / 10;

if (original == reversed) {

[Link]("Palindrome number");

} else {

[Link]("Not a palindrome");

}}}
ASSIGNMENT NO. 5:
Write a program to display the student name, roll no and age of a student
using class and object concept.

Program:
import [Link];

class Student {

String name;

int rollNo;

int age;

void setData(String n, int r, int a) {

name = n;

rollNo = r;

age = a;

void display() {

[Link]("Name: " + name);

[Link]("Roll No: " + rollNo);

[Link]("Age: " + age);

public class StudentDemo {

public static void main(String[] args) {

Scanner sc = new Scanner([Link]);

Student s1 = new Student();

[Link]("Enter name: ");

String name = [Link]();


[Link]("Enter roll no: ");

int roll = [Link]();

[Link]("Enter age: ");

int age = [Link]();

[Link](name, roll, age);

[Link]();

}
ASSIGNMENT NO. 6 :
Write separate programs that shows the implementation of

(i) static variable and static member function.

Program:
class StaticDemo {

static int count = 0;

StaticDemo() {

count++;

static void displayCount() {

[Link]("Total objects created: " + count);

public class StaticExample {

public static void main(String[] args) {

StaticDemo obj1 = new StaticDemo();

StaticDemo obj2 = new StaticDemo();

StaticDemo obj3 = new StaticDemo();

[Link]();

}
ASSIGNMENT NO. 6 :
Write separate programs that shows the implementation of

(ii) static block concept

Program:
class StaticBlockDemo {

static int x;

static {

x = 100;

[Link]("Static block executed");

void display() {

[Link]("Value of x: " + x);

public class StaticBlockExample {

public static void main(String[] args) {

StaticBlockDemo obj = new StaticBlockDemo();

[Link]();

}
ASSIGNMENT NO. 7 :
Write a program that shows the use of default, parameterized and copy
constructor.

Program:
class Student {

String name;

int age;

// Default constructor

Student() {

name = "Unknown";

age = 0;

// Parameterized constructor

Student(String name, int age) {

[Link] = name;

[Link] = age;

// Copy constructor

Student(Student s) {

[Link] = [Link];

[Link] = [Link];

void display() {

[Link]("Name: " + name + ", Age: " + age);}}

public class ConstructorDemo {

public static void main(String[] args) {


Student s1 = new Student(); // default

Student s2 = new Student("Arun", 20); // parameterized

Student s3 = new Student(s2); // copy

[Link]();

[Link]();

[Link]();}}

You might also like