Java 1 To 8 Praclab
Java 1 To 8 Praclab
Java 1 To 8 Praclab
class HelloWorld {
System.out.println("Hello, World!");
Output:
System.out.println("The sum of " + num1 + " and " + num2 + " is " + sum);
}
Output:
Output:
3. WAP to calculate Perimeter of rectangle
import java.util.Scanner;
Output:
Practical no. 2
1:-WAP in java to print even and odd number between 100 to 150 using for
loop.
public class Main {
if (i % 2 == 0) {
System.out.println(i);
if (i % 2 != 0) {
System.out.println(i);
Output:-
2. WAP in java to print Fibonacci series upto 100 using while loop.
public class Main {
int first = 0;
int second = 1;
int next = 0;
first = second;
second = next;
Output:-
if (isPrime(i)) {
if (n <= 1) {
return false;
if (n % i == 0) {
return false;
}
return true;
Output:-
System.out.println("Enter a number:");
int reversedNumber = 0;
while (number != 0) {
number /= 10;
}
Output:-
System.out.println("Enter a number:");
originalNumber = number;
while (originalNumber != 0) {
originalNumber /= 10;
Output:-
1. Java Array Program to Find the Largest Element in an Array
public class FindLargestElement {
largest = numbers[i];
Output:
2. Java Array Program to Copy All the Elements of One Array to Another Array
public class CopyArrayElements {
destinationArray[i] = sourceArray[i];
Output:
3. Java Array Program to Check Whether Two Matrices Are Equal or Not
import java.util.Scanner;
matrix1[i][j] = sc.nextInt();
}
matrix2[i][j] = sc.nextInt();
if (matrix1[i][j] != matrix2[i][j]) {
isEqual = false;
break;
if (!isEqual) {
break;
if (isEqual) {
} else {
sc.close();
Output:
4. Java Array Program to Find the Transpose
public class TransposeArray {
transposedArray[j][i] = originalArray[i][j];
System.out.println("Original Array:");
System.out.println();
System.out.println("Transposed Array:");
System.out.println();
Output:
scanner.close();
if (numbers[i] == target) {
found = true;
position = i;
break;
if (found) {
System.out.println("Element " + target + " is found at position " + position + " in the array.");
} else {
Output:
int n = arr.length;
System.out.println("Original Array:");
printArray(arr);
bubbleSort(arr);
System.out.println("\nSorted Array:");
printArray(arr);
int n = arr.length;
arr[j + 1] = temp;
}
System.out.println();
Output:
Practical 4
1. Java Program to Count Number of Objects Created for Class Passing and
Returning Objects in Java
class ClassCounter {
private static int classCount = 0;
ClassCounter() {
classCount++;
}
class ClassCreator {
static ClassCounter createCounter() {
return new ClassCounter();
}
}
Output:-
Output:-
Output:-
this.name = name;
this.age = age;
this.salary = salary;
return name;
return age;
return salary;
this.bonus = bonus;
@Override
@Override
super.display();
this.productivity = productivity;
@Override
@Override
super.display();
employees.add(manager);
employees.add(clerk);
employee.display();
System.out.println();
}
Output:-