0% found this document useful (0 votes)
10 views73 pages

JavaAssigments 0 DIVISION H 13 389 VIK

The document outlines programming assignments for the Master of Computer Application program at Lok Jagruti Kendra University for the academic year 2024-2025. It includes various tasks such as printing even numbers, calculating the sum of natural numbers, factorial calculation, reversing a number, checking for palindromes, and implementing a menu-driven calculator, among others. Each assignment provides implementation details, test cases, and expected outputs, authored by Shruti Surve.

Uploaded by

miteshsharma301
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)
10 views73 pages

JavaAssigments 0 DIVISION H 13 389 VIK

The document outlines programming assignments for the Master of Computer Application program at Lok Jagruti Kendra University for the academic year 2024-2025. It includes various tasks such as printing even numbers, calculating the sum of natural numbers, factorial calculation, reversing a number, checking for palindromes, and implementing a menu-driven calculator, among others. Each assignment provides implementation details, test cases, and expected outputs, authored by Shruti Surve.

Uploaded by

miteshsharma301
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
You are on page 1/ 73

1

LOK JAGRUTI KENDRA UNIVERSITY


School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String

1. Assignments for (for ) Loop


1.1 Print Even Numbers

Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation: 19/02/2025
Time of Creation : 07:00 PM

public class EvenNumbers {


public static void main(String[] args) {
System.out.print("Even numbers between 1 and 50: ");
for (int i = 2; i <= 50; i += 2) {
System.out.print(i + " ");
}
}
}
Test Cases :
Input: No input required
Expected Output: 2 4 6 8 ... 50

1.2 Sum of First 100 Natural Numbers


Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation: 19/02/2025

MCA- Noon Batch : DIVISION :-- H


Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
2
LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
Time of Creation : 07:10 PM

public class SumOfNumbers {


public static void main(String[] args) {
int sum = 0;
for (int i = 1; i <= 100; i++) {
sum += i;
}
System.out.println("Sum of first 100 natural numbers: " + sum);
}
}
Test Case:
Expected Output: 5050

1.3 Factorial Calculation


Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation: 19/02/2025
Time of Creation : 07:15 PM

import java.util.Scanner;
public class Factorial {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number: ");
int num = sc.nextInt();
int fact = 1;
for (int i = 1; i <= num; i++) {
fact *= i;
}
System.out.println("Factorial of " + num + " is: " + fact);
MCA- Noon Batch : DIVISION :-- H
Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
3
LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
sc.close();
}
}
Test Case 1:
Input: 5
Expected Output: 120

2. Assignments for while Loop


2.1 Reverse a Number
Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation: 19/02/2025
Time of Creation : 07:25 PM

import java.util.Scanner;
public class ReverseNumber {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number: ");
int num = sc.nextInt();
int reversed = 0;
while (num != 0) {
int digit = num % 10;
reversed = reversed * 10 + digit;
num /= 10;
}
System.out.println("Reversed Number: " + reversed);
sc.close();
}
}

MCA- Noon Batch : DIVISION :-- H


Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
4
LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
Test Case 1:
Input: 12345
Expected Output: 54321

2.2 Check Palindrome


Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation: 19/02/2025
Time of Creation : 07:30 PM

import java.util.Scanner;
public class PalindromeNumber {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number: ");
int num = sc.nextInt();
int originalNum = num;
int reversed = 0;
while (num != 0) {
int digit = num % 10;
reversed = reversed * 10 + digit;
num /= 10;
}
if (originalNum == reversed) {
System.out.println("Palindrome");
} else {
System.out.println("Not a Palindrome");
}
sc.close();
}

MCA- Noon Batch : DIVISION :-- H


Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
5
LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
}
Test Case :
Input: 121
Expected Output: Palindrome

Practical No : 2.3 Find Largest Digit in a Number


Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation: 19/02/2025
Time of Creation : 07:35PM

import java.util.Scanner;
public class LargestDigit {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number: ");
int num = sc.nextInt();
int largest = 0;
while (num != 0) {
int digit = num % 10;
if (digit > largest) {
largest = digit;
}
num /= 10;
}
System.out.println("Largest digit: " + largest);
sc.close();
}
}
Test Case 1:
MCA- Noon Batch : DIVISION :-- H
Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
6
LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
Input: 9876
Expected Output: 9
3. Assignments for do-while Loop
Practical No : 3.1 Menu-Driven Calculator
Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation: 19/02/2025
Time of Creation : 07:40 PM

import java.util.Scanner;
public class Calculator {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int choice;
do {
System.out.println("\nMenu:");
System.out.println("1. Addition");
System.out.println("2. Subtraction");
System.out.println("3. Multiplication");
System.out.println("4. Division");
System.out.println("5. Exit");
System.out.print("Enter your choice: ");
choice = sc.nextInt();
if (choice >= 1 && choice <= 4) {
System.out.print("Enter first number: ");
double num1 = sc.nextDouble();
System.out.print("Enter second number: ");
double num2 = sc.nextDouble();
double result = 0;
switch (choice) {
MCA- Noon Batch : DIVISION :-- H
Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
7
LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
case 1: result = num1 + num2; break;
case 2: result = num1 - num2; break;
case 3: result = num1 * num2; break;
case 4: result = num2 != 0 ? num1 / num2 : Double.NaN; break;
}
System.out.println("Result: " + result);
} else if (choice != 5) {
System.out.println("Invalid choice. Try again.");
}
} while (choice != 5);
System.out.println("Exiting Calculator...");
sc.close();
}
}
Test Case 1:
Input: 1, 5, 3
Expected Output: 8

Practical No : 3.2 Sum of Digits


Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation: 19/02/2025
Time of Creation : 07:40 PM

import java.util.Scanner;
public class SumOfDigits {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number: ");
int num = sc.nextInt();
MCA- Noon Batch : DIVISION :-- H
Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
8
LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
int sum = 0;
do {
sum += num % 10;
num /= 10;
} while (num > 0);
System.out.println("Sum of digits: " + sum);
sc.close();
}
}
Test Case 1:
Input: 123
Expected Output: 6

Practical No : 3.3 Guess the Number Game


Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:55 PM

import java.util.Scanner;

import java.util.Random;

public class GuessNumber {

public static void main(String[] args) {

MCA- Noon Batch : DIVISION :-- H


Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
9
LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
Scanner sc = new Scanner(System.in);

Random rand = new Random();

int secretNumber = rand.nextInt(100) + 1; // Random number between 1-100

int guess;

do {

System.out.print("Guess a number (1-100): ");

guess = sc.nextInt();

if (guess < secretNumber) {

System.out.println("Too low! Try again.");

} else if (guess > secretNumber) {

System.out.println("Too high! Try again.");

} else {

System.out.println("Correct Guess!");

} while (guess != secretNumber);

sc.close();

MCA- Noon Batch : DIVISION :-- H


Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
1
0 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
Test Case 1:
Input: User keeps guessing
Expected Output: "Correct Guess!" after the right number is guessed

4. Assignments for Enhanced for Loop


Practical No : 4.1 Find Maximum in Array
Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 08:50 PM

public class MaxInArray {


public static void main(String[] args) {
int[] numbers = {10, 20, 5, 30};
int max = numbers[0];
for (int num : numbers) {
if (num > max) {
max = num;
}
}
System.out.println("Maximum value: " + max);
}
}
Test Case 1:
Input: [10, 20, 5, 30]
Expected Output: 30

Practical No : 4.2 Calculate Average of Array


public class AverageArray {
public static void main(String[] args) {
int[] numbers = {10, 20, 30, 40};
int sum = 0;
for (int num : numbers) {
sum += num;
MCA- Noon Batch : DIVISION :-- H
Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
1
1 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
}
double average = (double) sum / numbers.length;
System.out.println("Average: " + average);
}
}
Test Case 1:
Input: [10, 20, 30, 40]
Expected Output: 25.0

Practical No : 4.3 Count Vowels in String Array


Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM

public class CountVowels {

public static void main(String[] args) {

String[] words = {"apple", "orange", "grape"};

for (String word : words) {

int vowelCount = 0;

for (char ch : word.toCharArray()) {

if ("AEIOUaeiou".indexOf(ch) != -1) {

vowelCount++;

}
MCA- Noon Batch : DIVISION :-- H
Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
1
2 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
}

System.out.println("Vowels in " + word + ": " + vowelCount);

}
Test Case 1:
Input: ["apple", "orange", "grape"]
Expected Output: 2, 3, 2

5. Assignments for Nested Loops


Practical No : 5.1 Multiplication Table (1-10)
Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM
public class MultiplicationTable {
public static void main(String[] args) {
for (int i = 1; i <= 10; i++) {
for (int j = 1; j <= 10; j++) {
System.out.print(i * j + "\t");
}
System.out.println();
}
}
}
Test Case 1:
Expected Output: Multiplication table from 1 to 10

Practical No : 5.2 Pyramid Pattern


MCA- Noon Batch : DIVISION :-- H
Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
1
3 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM
import java.util.Scanner;
public class PyramidPattern {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter number of rows: ");
int rows = sc.nextInt();
for (int i = 1; i <= rows; i++) {
for (int j = 1; j <= (2 * i - 1); j++) {
System.out.print("*");
}
System.out.println();
}
sc.close();
}
}
Test Case 1:
Input: 5
*
***
*****
*******
*********

Practical No : 5.3 Prime Numbers from 1 to 100


Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
MCA- Noon Batch : DIVISION :-- H
Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
1
4 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM
public class PrimeNumbers {
public static void main(String[] args) {
System.out.print("Prime numbers from 1 to 100: ");
for (int num = 2; num <= 100; num++) {
boolean isPrime = true;
for (int i = 2; i <= Math.sqrt(num); i++) {
if (num % i == 0) {
isPrime = false;
break;
}
}
if (isPrime) {
System.out.print(num + " ");
}
}
}
}
Test Case 1:
Expected Output: 2, 3, 5, 7, ..., 97

More Assignments Using Nested Loops


Practical No : 6.1 Floyd's Triangle
Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM
import java.util.Scanner;
public class FloydsTriangle {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter number of rows: ");
int rows = sc.nextInt();
MCA- Noon Batch : DIVISION :-- H
Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
1
5 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
int num = 1;
for (int i = 1; i <= rows; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(num++ + " ");
}
System.out.println();
}
sc.close();
}
}
Test Case 1:
Input: 5
Expected Output:
1
23
456
7 8 9 10
11 12 13 14 15

Practical No : 6.2 Pascal’s Triangle


Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM
import java.util.Scanner;
public class PascalsTriangle {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter number of rows: ");
int rows = sc.nextInt();
for (int i = 0; i < rows; i++) {
int num = 1;
for (int j = 0; j <= i; j++) {
System.out.print(num + " ");
num = num * (i - j) / (j + 1);
MCA- Noon Batch : DIVISION :-- H
Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
1
6 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
}
System.out.println();
}
sc.close();
}
}
Test Case 1:
Input: 5
Expected Output:
1
11
121
1331
14641

Practical No : 6.3 Print Diamond Pattern


Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM
import java.util.Scanner;
public class DiamondPattern {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter number of rows: ");
int rows = sc.nextInt();
for (int i = 1; i <= rows; i += 2) {
for (int j = 0; j < (rows - i) / 2; j++) {
System.out.print(" ");
}
for (int j = 0; j < i; j++) {
System.out.print("*");
}

MCA- Noon Batch : DIVISION :-- H


Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
1
7 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
System.out.println();
}
for (int i = rows - 2; i > 0; i -= 2) {
for (int j = 0; j < (rows - i) / 2; j++) {
System.out.print(" ");
}
for (int j = 0; j < i; j++) {
System.out.print("*");
}
System.out.println();
}
sc.close();
}
}
Test Case 1:
Input: 5
Expected Output:
*
***
*****
***
*
Practical No : 6.4 Multiplication Table Grid
Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM
import java.util.Scanner;
public class MultiplicationGrid {
public static void main(String[] args) {
MCA- Noon Batch : DIVISION :-- H
Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
1
8 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
Scanner sc = new Scanner(System.in);
System.out.print("Enter grid size: ");
int size = sc.nextInt();
for (int i = 1; i <= size; i++) {
for (int j = 1; j <= size; j++) {
System.out.print(i * j + "\t");
}
System.out.println();
}
sc.close();
}
}
Test Case:
Input: 5
Expected Output:
1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20
5 10 15 20 25

Practical No : 6.5 Alphabet Pyramid


Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM
import java.util.Scanner;
public class AlphabetPyramid {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
MCA- Noon Batch : DIVISION :-- H
Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
1
9 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
System.out.print("Enter number of rows: ");
int rows = sc.nextInt();
for (int i = 1; i <= rows; i++) {
for (char ch = 'A'; ch < 'A' + i; ch++) {
System.out.print(ch + " ");
}
System.out.println();
}
sc.close();
}
}
Test Case:
Input: 5
A
AB
ABC
ABCD
ABCDE
Practical No : 6.6 Check Symmetry in 2D Array
Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM
import java.util.Scanner;
public class SymmetricMatrix {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter matrix size: ");
int n = sc.nextInt();
int[][] matrix = new int[n][n];
MCA- Noon Batch : DIVISION :-- H
Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
2
0 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
System.out.println("Enter matrix elements:");
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
matrix[i][j] = sc.nextInt();
}
}
boolean symmetric = true;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (matrix[i][j] != matrix[j][i]) {
symmetric = false;
break;
}
}
}
if (symmetric) {
System.out.println("Symmetric");
} else {
System.out.println("Not Symmetric");
}
sc.close();
}
}
Test Case:
123
245
356

Practical No : 6.7 Hollow Rectangle


Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos

MCA- Noon Batch : DIVISION :-- H


Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
2
1 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM
import java.util.Scanner;
public class HollowRectangle {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter rows: ");
int rows = sc.nextInt();
System.out.print("Enter columns: ");
int cols = sc.nextInt();
for (int i = 1; i <= rows; i++) {
for (int j = 1; j <= cols; j++) {
if (i == 1 || i == rows || j == 1 || j == cols) {
System.out.print("*");
} else {
System.out.print(" ");
}
}
System.out.println();
}
sc.close();
}
}
Test Case:
Input: 5 7
*******
* *
* *
* *
*******
Practical No : 6.8 Number Pattern
Implementation :
This program demonstrates input validation, code modularity,

MCA- Noon Batch : DIVISION :-- H


Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
2
2 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM
import java.util.Scanner;
public class NumberPattern {
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter number of rows: ");
int rows = sc.nextInt();
for (int i = 1; i <= rows; i++)
{
for (int j = 1; j <= i; j++) {
System.out.print(j + " ");
}
System.out.println();
}
sc.close();
}
}
Test Case:
Input: 5
1
12
123
1234
12345

Practical No : 6.9 Spiral Matrix


Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
MCA- Noon Batch : DIVISION :-- H
Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
2
3 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM
import java.util.Scanner;
public class SpiralMatrix {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter matrix size: ");
int n = sc.nextInt();
int[][] matrix = new int[n][n];
int num = 1, rowStart = 0, rowEnd = n - 1, colStart = 0, colEnd = n - 1;
while (rowStart <= rowEnd && colStart <= colEnd) {
for (int i = colStart; i <= colEnd; i++) matrix[rowStart][i] = num++;
rowStart++;
for (int i = rowStart; i <= rowEnd; i++) matrix[i][colEnd] = num++;
colEnd--;
for (int i = colEnd; i >= colStart; i--) matrix[rowEnd][i] = num++;
rowEnd--;
for (int i = rowEnd; i >= rowStart; i--) matrix[i][colStart] = num++;
colStart++;
}
for (int[] row : matrix) {
for (int val : row) {
System.out.print(val + "\t");
}
System.out.println();
}
sc.close();
}
}
Test Case:
Input: 4

MCA- Noon Batch : DIVISION :-- H


Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
2
4 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String

1 2 3 4
12 13 14 5
11 16 15 6
10 9 8 7
Practical No : 6.10 Zigzag Pattern
Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM
import java.util.Scanner;
public class ZigzagPattern {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter rows: ");
int rows = sc.nextInt();
System.out.print("Enter columns: ");
int cols = sc.nextInt();
int num = 1;
for (int i = 0; i < rows; i++) {
if (i % 2 == 0) {
for (int j = 0; j < cols; j++) {
System.out.print(num++ + " ");
}
} else {
num += cols - 1;
for (int j = 0; j < cols; j++) {
System.out.print(num-- + " ");
}
num += cols + 1;
MCA- Noon Batch : DIVISION :-- H
Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
2
5 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
}
System.out.println();
}
sc.close();
}
}
Test Case:
Input: 5 5
1 2 3 4 5
10 9 8 7 6
11 12 13 14 15
20 19 18 17 16
21 22 23 24 25
Roll No : 34
Enrollment No :24004401110338
Author : Manohar Jangid
Date of Creation: 11/02/2025
Time of Creation :12:30 PM

Practical Assignments for Decision Control Statements in Java.


7 If Statement
Q1: Check if a number is positive, negative, or zero
Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM
import java.util.Scanner;
public class NumberCheck {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

MCA- Noon Batch : DIVISION :-- H


Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
2
6 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
// Input: Read a number from the user
System.out.print("Enter a number: ");
int num = scanner.nextInt();
// Decision Making Using If Statement
if (num > 0) {
System.out.println("The number is Positive.");
}
if (num < 0) {
System.out.println("The number is Negative.");
}
if (num == 0) {
System.out.println("The number is Zero.");
}
scanner.close();
}
}
Test Cases:
Test Case # Input Expected Output
1 10 The number is Positive.
2 -5 The number is Negative.
3 0 The number is Zero.

Q2. Determine if a given year is a leap year


Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM
import java.util.Scanner;
public class LeapYearCheck {
public static void main(String[] args) {
MCA- Noon Batch : DIVISION :-- H
Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
2
7 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a year: ");
int year = scanner.nextInt();
if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
System.out.println(year + " is a Leap Year.");
}
if (!((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))) {
System.out.println(year + " is NOT a Leap Year.");
}
scanner.close();
}
}
Test Cases
Test Case Input Expected Output
1 2024 2024 is a Leap Year.
2 1900 1900 is NOT a Leap Year.
3 2000 2000 is a Leap Year.

Q3. Check if a person is eligible to vote.


Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM
import java.util.Scanner;
public class VotingEligibility {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter your age: ");
int age = scanner.nextInt();
if (age >= 18) {
MCA- Noon Batch : DIVISION :-- H
Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
2
8 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
System.out.println("You are eligible to vote.");
}
if (age < 18) {
System.out.println("You are not eligible to vote.");
}
scanner.close();
}
}
Test Cases
Test Case Input Expected Output
1 20 You are eligible to vote.
2 17 You are not eligible to vote.
3 18 You are eligible to vote.

2. If-Else Statement
Q4. Check if a number is even or odd
Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM
import java.util.Scanner;
public class EvenOddCheck {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a number: ");
int num = scanner.nextInt();
if (num % 2 == 0) {
System.out.println("The number is Even.");
} else {
System.out.println("The number is Odd.");
MCA- Noon Batch : DIVISION :-- H
Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
2
9 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
}
scanner.close();
}
}
Test Cases
Test Case Input Expected Output
1 10 The number is Even.
2 7 The number is Odd.
3 0 The number is Even.

Q5. Compare two numbers and display the larger one.


Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM
import java.util.Scanner;
public class LargerNumber {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter first number: ");
int num1 = scanner.nextInt();
System.out.print("Enter second number: ");
int num2 = scanner.nextInt();
if (num1 > num2) {
System.out.println(num1 + " is larger.");
} else if (num2 > num1) {
System.out.println(num2 + " is larger.");
} else {
System.out.println("Both numbers are equal.");
}
MCA- Noon Batch : DIVISION :-- H
Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
3
0 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
scanner.close();
}
}
Test Cases
Test Case Input Expected Output
1 10, 20 20 is larger.
2 50, 25 50 is larger.
3 30, 30 Both numbers are equal.

Q6. Calculate the grade based on marks


Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM
import java.util.Scanner;
public class StudentGrade {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter marks: ");
int marks = scanner.nextInt();
if (marks >= 50) {
System.out.println("Pass");
} else {
System.out.println("Fail");
}
scanner.close();
}
}
Test Cases

MCA- Noon Batch : DIVISION :-- H


Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
3
1 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
Test Case Input Expected Output
1 75 Pass
2 45 Fail
3 50 Pass

2. Nested If Statement
Q7. Find the largest of three numbers
Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM
import java.util.Scanner;
public class LargestOfThree {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter three numbers: ");
int num1 = scanner.nextInt();
int num2 = scanner.nextInt();
int num3 = scanner.nextInt();
if (num1 >= num2 && num1 >= num3) {
System.out.println(num1 + " is the largest.");
}
else if (num2 >= num1 && num2 >= num3) {
System.out.println(num2 + " is the largest.");
}
else {
System.out.println(num3 + " is the largest.");
}
scanner.close();
}
MCA- Noon Batch : DIVISION :-- H
Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
3
2 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
}
Test Cases
Test Case Input Expected Output
1 10, 20, 30 30 is the largest.
2 50, 25, 40 50 is the largest.
3 30, 30, 30 30 is the largest.

Q8. Check whether a triangle is valid based on its three angles


Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM
import java.util.Scanner;
public class TriangleValidity {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter three angles of the triangle: ");
int angle1 = scanner.nextInt();
int angle2 = scanner.nextInt();
int angle3 = scanner.nextInt();
if (angle1 + angle2 + angle3 == 180) {
System.out.println("The triangle is valid.");
} else {
System.out.println("The triangle is not valid.");
}
scanner.close();
}
}
Test Cases

MCA- Noon Batch : DIVISION :-- H


Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
3
3 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
Test Case Input Expected Output
1 60, 60, 60 The triangle is valid.
2 90, 45, 45 The triangle is valid.
3 30, 60, 70 The triangle is not valid

Q9. Classify a person based on age


Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM
import java.util.Scanner;
public class AgeClassification {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter age: ");
int age = scanner.nextInt();
if (age < 12) {
System.out.println("Child");
} else if (age >= 12 && age <= 17) {
System.out.println("Teenager");
} else {
System.out.println("Adult");
}
scanner.close();
}
}
Test Cases
Test Case Input Expected Output
1 10 Child
2 15 Teenager
MCA- Noon Batch : DIVISION :-- H
Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
3
4 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
Test Case Input Expected Output
3 20 Adult

4. If-Else-If Ladder
Q10. Assign grades based on marks
Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM
import java.util.Scanner;
public class GradeAssignment {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter marks: ");
int marks = scanner.nextInt();
if (marks >= 90) {
System.out.println("Grade: A+");
} else if (marks >= 80) {
System.out.println("Grade: A");
} else if (marks >= 70) {
System.out.println("Grade: B");
} else if (marks >= 60) {
System.out.println("Grade: C");
} else {
System.out.println("Grade: F");
}
scanner.close();
}
}
Test Cases
MCA- Noon Batch : DIVISION :-- H
Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
3
5 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
Test Case Input Expected Output
1 92 Grade: A+
2 85 Grade: A
3 45 Grade: F

Q11. Calculate electricity bill charges based on units consumed


Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM
import java.util.Scanner;
public class ElectricityBill {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter units consumed: ");
int units = scanner.nextInt();
int charge;
if (units <= 100) {
charge = units * 3;
} else if (units <= 200) {
charge = (100 * 3) + ((units - 100) * 5);
} else {
charge = (100 * 3) + (100 * 5) + ((units - 200) * 8);
}
System.out.println("Total bill: ₹" + charge);
scanner.close();
}
}
Test Cases

MCA- Noon Batch : DIVISION :-- H


Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
3
6 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
Test Case Input Expected Output
1 90 Total bill: ₹270
2 150 Total bill: ₹550
3 250 Total bill: ₹1150

Q12. Classify a given character


Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM
import java.util.Scanner;
public class CharacterClassification {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a character: ");
char ch = scanner.next().charAt(0);
if (Character.isUpperCase(ch)) {
System.out.println("Uppercase letter");
} else if (Character.isLowerCase(ch)) {
System.out.println("Lowercase letter");
} else if (Character.isDigit(ch)) {
System.out.println("Digit");
} else {
System.out.println("Special character");
}
scanner.close();
}
}
Test Cases

MCA- Noon Batch : DIVISION :-- H


Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
3
7 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
Test Case Input Expected Output
1 A Uppercase letter
2 b Lowercase letter
3 5 Digit

5. Switch Statement
Q13. Create a calculator program using a switch statement
Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM
import java.util.Scanner;
public class Calculator {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter first number: ");
double num1 = scanner.nextDouble();
System.out.print("Enter second number: ");
double num2 = scanner.nextDouble();
System.out.print("Enter operation (+, -, *, /): ");
char operator = scanner.next().charAt(0);
double result;
switch (operator) {
case '+':
result = num1 + num2;
System.out.println("Result: " + result);
break;
case '-':
result = num1 - num2;
System.out.println("Result: " + result);
MCA- Noon Batch : DIVISION :-- H
Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
3
8 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
break;
case '*':
result = num1 * num2;
System.out.println("Result: " + result);
break;
case '/':
if (num2 != 0) {
result = num1 / num2;
System.out.println("Result: " + result);
} else {
System.out.println("Cannot divide by zero.");
}
break;
default:
System.out.println("Invalid operation.");
}
scanner.close();
}
}
Test Cases
Test Case Input Expected Output
1 5, 3, + Result: 8.0
2 10, 5, / Result: 2.0
3 4, 0, / Cannot divide by zero.

Q14. Display the name of the day of the week based on a number
Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM

MCA- Noon Batch : DIVISION :-- H


Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
3
9 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
import java.util.Scanner;
public class DayOfWeek {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a number (1-7): ");
int day = scanner.nextInt();
switch (day) {
case 1: System.out.println("Monday"); break;
case 2: System.out.println("Tuesday"); break;
case 3: System.out.println("Wednesday"); break;
case 4: System.out.println("Thursday"); break;
case 5: System.out.println("Friday"); break;
case 6: System.out.println("Saturday"); break;
case 7: System.out.println("Sunday"); break;
default: System.out.println("Invalid number.");
}
scanner.close();
}
}
Test Cases
Test Case Input Expected Output
1 3 Wednesday
2 6 Saturday
3 9 Invalid number.

Q15. Display the number of days in a month


Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM

MCA- Noon Batch : DIVISION :-- H


Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
4
0 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
import java.util.Scanner;
public class DaysInMonth {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter month number (1-12): ");
int month = scanner.nextInt();
switch (month) {
case 1: case 3: case 5: case 7: case 8: case 10: case 12:
System.out.println("31 days");
break;
case 4: case 6: case 9: case 11:
System.out.println("30 days");
break;
case 2:
System.out.println("28 or 29 days (Leap year dependent)");
break;
default:
System.out.println("Invalid month number.");
}
scanner.close();
}
}
Test Cases
Test Case Input Expected Output
1 2 28 or 29 days (Leap year dependent)
2 7 31 days
3 13 Invalid month number.

6. Ternary Operator
Q16. Find the smallest of two numbers using the ternary operator
Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.

MCA- Noon Batch : DIVISION :-- H


Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
4
1 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM
import java.util.Scanner;
public class SmallestNumber {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter two numbers: ");
int num1 = scanner.nextInt();
int num2 = scanner.nextInt();
int smallest = (num1 < num2) ? num1 : num2;
System.out.println("Smallest number: " + smallest);
scanner.close();
}
}
Test Cases
Test Case Input Expected Output
1 5, 10 Smallest number: 5
2 20, 15 Smallest number: 15
3 -5, -10 Smallest number: -10

Q17. Check if a number is divisible by 5 using the ternary operator


Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM
import java.util.Scanner;
public class DivisibleByFive {
public static void main(String[] args) {
MCA- Noon Batch : DIVISION :-- H
Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
4
2 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a number: ");
int num = scanner.nextInt();
String result = (num % 5 == 0) ? "Divisible by 5" : "Not divisible by 5";
System.out.println(result);
scanner.close();
}
}
Test Cases
Test Case Input Expected Output
1 25 Divisible by 5
2 19 Not divisible by 5
3 -10 Divisible by 5

Q18. Assign "Pass" or "Fail" based on marks using the ternary


operator
Java Program
Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM
import java.util.Scanner;
public class PassFail {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter marks: ");
int marks = scanner.nextInt();
String result = (marks >= 50) ? "Pass" : "Fail";
System.out.println(result);
scanner.close();
MCA- Noon Batch : DIVISION :-- H
Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
4
3 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
}
}
Test Cases
Test Case Input Expected Output
1 75 Pass
2 40 Fail
3 50 Pass

8. Combination of Decision Control Statements


Q19. Determine if a given year is a leap year using nested if and switch
Java Program
Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM
import java.util.Scanner;
public class LeapYearCheck {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a year: ");
int year = scanner.nextInt();
if (year % 4 == 0) {
if (year % 100 == 0) {
if (year % 400 == 0) {
System.out.println("Leap Year");
} else {
System.out.println("Not a Leap Year");
}
} else {
System.out.println("Leap Year");
MCA- Noon Batch : DIVISION :-- H
Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
4
4 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
}
} else {
System.out.println("Not a Leap Year");
}
scanner.close();
}
}
Test Cases
Test Case Input Expected Output
1 2020 Leap Year
2 1900 Not a Leap Year
3 2000 Leap Year

Q20. Calculate the income tax based on slabs


Java Program
Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM
import java.util.Scanner;
public class IncomeTaxCalculator {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter income: ₹");
double income = scanner.nextDouble();
double tax = 0;
if (income <= 250000) {
tax = 0;
} else if (income <= 500000) {
tax = (income - 250000) * 0.05;
MCA- Noon Batch : DIVISION :-- H
Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
4
5 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
} else if (income <= 1000000) {
tax = (250000 * 0.05) + (income - 500000) * 0.20;
} else {
tax = (250000 * 0.05) + (500000 * 0.20) + (income - 1000000) * 0.30;
}
System.out.println("Income Tax: ₹" + tax);
scanner.close();
}
}
Test Cases
Test Case Input Expected Output
1 ₹3,00,000 ₹2,500
2 ₹7,00,000 ₹45,000
3 ₹12,00,000 ₹1,50,000

Q21. Simulate a basic login system with three attempts


Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM
import java.util.Scanner;
public class LoginSystem {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String correctUsername = "admin";
String correctPassword = "password123";
int attempts = 3;
while (attempts > 0) {
System.out.print("Enter username: ");
String username = scanner.next();
MCA- Noon Batch : DIVISION :-- H
Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
4
6 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
System.out.print("Enter password: ");
String password = scanner.next();
if (username.equals(correctUsername) &&
password.equals(correctPassword)) {
System.out.println("Login successful!");
break;
} else {
attempts--;
System.out.println("Incorrect credentials. Attempts left: " + attempts);
}
}
if (attempts == 0) {
System.out.println("Account locked.");
}
scanner.close();
}
}
Test Cases
Test
Input Expected Output
Case
admin,
1 Login successful!
password123
2 user, pass Incorrect credentials. Attempts left: 2
Incorrect credentials. Attempts left: 0,
3 wrong, 123
Account locked.

Q22. Simulate a vending machine using switch statements


Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
MCA- Noon Batch : DIVISION :-- H
Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
4
7 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
Time of Creation : 07:20 PM
import java.util.Scanner;
public class VendingMachine {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Vending Machine Menu:");
System.out.println("1. Chips - ₹20");
System.out.println("2. Soda - ₹30");
System.out.println("3. Chocolate - ₹50");
System.out.println("4. Juice - ₹40");
System.out.print("Enter your choice (1-4): ");
int choice = scanner.nextInt();
switch (choice) {
case 1:
System.out.println("You selected Chips. Price: ₹20");
break;
case 2:
System.out.println("You selected Soda. Price: ₹30");
break;
case 3:
System.out.println("You selected Chocolate. Price: ₹50");
break;
case 4:
System.out.println("You selected Juice. Price: ₹40");
break;
default:
System.out.println("Invalid choice!");
}
scanner.close();
}
}
Test Cases
Test Case Input Expected Output
1 1 You selected Chips. Price: ₹20
MCA- Noon Batch : DIVISION :-- H
Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
4
8 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
Test Case Input Expected Output
2 3 You selected Chocolate. Price: ₹50
3 5 Invalid choice!

Q23. Categorize a number as Positive Even, Positive Odd, Negative


Even, Negative Odd, or Zero
Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM
import java.util.Scanner;
public class NumberCategory {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a number: ");
int num = scanner.nextInt();
if (num == 0) {
System.out.println("Zero");
} else if (num > 0) {
System.out.println((num % 2 == 0) ? "Positive Even" : "Positive Odd");
} else {
System.out.println((num % 2 == 0) ? "Negative Even" : "Negative Odd");
}
scanner.close();
}
}
Test Cases
Test Case Input Expected Output
1 4 Positive Even
2 -7 Negative Odd
MCA- Noon Batch : DIVISION :-- H
Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
4
9 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
Test Case Input Expected Output
3 0 Zero

Q24. Implement a grading system based on marks and attendance


using nested if
Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM
import java.util.Scanner;
public class GradeSystem {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter marks: ");
int marks = scanner.nextInt();
System.out.print("Enter attendance percentage: ");
int attendance = scanner.nextInt();
if (marks >= 90) {
if (attendance >= 75) {
System.out.println("Grade: A+");
} else {
System.out.println("Grade: B (Low Attendance)");
}
} else if (marks >= 75) {
if (attendance >= 75) {
System.out.println("Grade: A");
} else {
System.out.println("Grade: C (Low Attendance)");
}
} else {
MCA- Noon Batch : DIVISION :-- H
Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
5
0 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
System.out.println("Grade: F (Fail)");
}
scanner.close();
}
}
Test Cases
Test Case Marks Attendance Expected Output
1 95 80% Grade: A+
2 85 70% Grade: B (Low Attendance)
3 50 90% Grade: F (Fail)

Q25. Check whether a triangle is valid based on angles


Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM
import java.util.Scanner;
public class TriangleCheck {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter three angles of the triangle: ");
int angle1 = scanner.nextInt();
int angle2 = scanner.nextInt();
int angle3 = scanner.nextInt();
if (angle1 + angle2 + angle3 == 180) {
System.out.println("Valid Triangle");
} else {
System.out.println("Invalid Triangle");
}
scanner.close();
MCA- Noon Batch : DIVISION :-- H
Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
5
1 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
}
}
Test Cases
Test Case Angles Expected Output
1 60, 60, 60 Valid Triangle
2 90, 45, 50 Invalid Triangle

Q26. Check if a character is uppercase, lowercase, digit, or special


character
Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM
import java.util.Scanner;
public class CharacterCheck {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a character: ");
char ch = scanner.next().charAt(0);
if (Character.isUpperCase(ch)) {
System.out.println("Uppercase Letter");
} else if (Character.isLowerCase(ch)) {
System.out.println("Lowercase Letter");
} else if (Character.isDigit(ch)) {
System.out.println("Digit");
} else {
System.out.println("Special Character");
}
scanner.close();
}
MCA- Noon Batch : DIVISION :-- H
Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
5
2 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
}
Test Cases
Test Case Input Expected Output
1 A Uppercase Letter
2 g Lowercase Letter
3 5 Digit
4 @ Special Character

Q27. Implement a basic ATM withdrawal system


Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM
import java.util.Scanner;
public class ATM {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int balance = 10000; // Initial balance
System.out.print("Enter withdrawal amount: ");
int withdraw = scanner.nextInt();
if (withdraw > balance) {
System.out.println("Insufficient Balance");
} else if (withdraw % 100 != 0) {
System.out.println("Enter amount in multiples of 100");
} else {
balance -= withdraw;
System.out.println("Withdrawal Successful. Remaining balance: ₹" +
balance);
}
scanner.close();
MCA- Noon Batch : DIVISION :-- H
Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
5
3 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
}
}
Test Cases
Test Case Input Expected Output
1 500 Withdrawal Successful. Remaining balance: ₹9500
2 13000 Insufficient Balance
3 345 Enter amount in multiples of 100

Q28. Determine if a given year is a leap year using nested if and switch
statements
Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM
import java.util.Scanner;
public class LeapYearCheck {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a year: ");
int year = scanner.nextInt();
if (year % 4 == 0) {
if (year % 100 == 0) {
switch (year % 400) {
case 0:
System.out.println(year + " is a Leap Year");
break;
default:
System.out.println(year + " is not a Leap Year");
}
} else {
MCA- Noon Batch : DIVISION :-- H
Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
5
4 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
System.out.println(year + " is a Leap Year");
}
} else {
System.out.println(year + " is not a Leap Year");
}
scanner.close();
}
}
Test Cases
Test Case Input Expected Output
1 2020 2020 is a Leap Year
2 1900 1900 is not a Leap Year
3 2000 2000 is a Leap Year

Q29. Find the factorial of a number using recursion


Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM
import java.util.Scanner;
public class FactorialRecursion {
public static int factorial(int n) {
return (n == 0 || n == 1) ? 1 : n * factorial(n - 1);
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a number: ");
int num = scanner.nextInt();
System.out.println("Factorial: " + factorial(num));
scanner.close();
MCA- Noon Batch : DIVISION :-- H
Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
5
5 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
}
}
Test Cases
Test Case Input Expected Output
1 5 120
2 7 5040
3 0 1

Q30. Count the number of digits in a number


Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM
import java.util.Scanner;
public class DigitCount {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a number: ");
int num = scanner.nextInt();
int count = 0;
while (num != 0) {
num /= 10;
count++;
}
System.out.println("Number of digits: " + count);
scanner.close();
}
}
Test Cases

MCA- Noon Batch : DIVISION :-- H


Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
5
6 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
Test Case Input Expected Output
1 1234 4
2 98765 5
3 0 1

Q31. Find the greatest common divisor (GCD) of two numbers


Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM
import java.util.Scanner;
public class GCD {
public static int findGCD(int a, int b) {
return (b == 0) ? a : findGCD(b, a % b);
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter first number: ");
int a = scanner.nextInt();
System.out.print("Enter second number: ");
int b = scanner.nextInt();
System.out.println("GCD: " + findGCD(a, b));
scanner.close();
}
}
Test Cases
Test Case Input Expected Output
1 8, 12 4
2 36, 60 12

MCA- Noon Batch : DIVISION :-- H


Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
5
7 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
Test Case Input Expected Output
3 17, 31 1

Q32. Find the least common multiple (LCM) of two numbers


Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM
import java.util.Scanner;
public class LCM {
public static int findGCD(int a, int b) {
return (b == 0) ? a : findGCD(b, a % b);
}
public static int findLCM(int a, int b) {
return (a * b) / findGCD(a, b);
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter first number: ");
int a = scanner.nextInt();
System.out.print("Enter second number: ");
int b = scanner.nextInt();
System.out.println("LCM: " + findLCM(a, b));
scanner.close();
}
}
Test Cases
Test Case Input Expected Output
1 8, 12 24
2 5, 7 35
MCA- Noon Batch : DIVISION :-- H
Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
5
8 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
Test Case Input Expected Output
3 21, 6 42

Array and Strings


Q1 Create and Print an Array
Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM
import java.util.Arrays;
public class PrintArray {
public static void main(String[] args) {
int[] arr = {10, 20, 30, 40, 50};
System.out.println("Array Elements: " + Arrays.toString(arr));
}
}
TestCase:
Input: {10, 20, 30, 40, 50}
Output: Array Elements: [10, 20, 30, 40, 50]

1. Find the Largest and Smallest Element

Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM

MCA- Noon Batch : DIVISION :-- H


Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
5
9 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
public class MinMaxArray {
public static void main(String[] args) {
int[] arr = {5, 2, 9, 1, 7};
int min = arr[0], max = arr[0];
for (int num : arr) {
if (num < min) min = num;
if (num > max) max = num;
}
System.out.println("Smallest: " + min);
System.out.println("Largest: " + max);
}
}
TestCase:
Input: {5, 2, 9, 1, 7}
Output:
Smallest:1
Largest: 9

2. Reverse an Array
Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM
import java.util.Arrays;
public class ReverseArray {
public static void main(String[] args) {
MCA- Noon Batch : DIVISION :-- H
Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
6
0 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
int[] arr = {1, 2, 3, 4, 5};
for (int i = 0, j = arr.length - 1; i < j; i++, j--) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
System.out.println("Reversed Array: " + Arrays.toString(arr));
}
}
Testcase:
Input: {1, 2, 3, 4, 5}
Output: Reversed Array: [5, 4, 3, 2, 1]

3. Sum and Average of Array Elements


Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM
public class SumAverage {
public static void main(String[] args) {
int[] arr = {5, 10, 15, 20};
int sum = 0;
for (int num : arr) {
sum += num;
}
double avg = (double) sum / arr.length;
System.out.println("Sum: " + sum + ", Average: " + avg);
}
}
TestCase:
Input: {5, 10, 15, 20}
Output: Sum: 50, Average: 12.5
MCA- Noon Batch : DIVISION :-- H
Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
6
1 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
4. Search an Element (Linear Search)
Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM
public class LinearSearch {
public static void main(String[] args) {
int[] arr = {10, 20, 30, 40, 50};
int key = 30;
boolean found = false;
for (int num : arr) {
if (num == key) {
found = true;
break;
}
}
System.out.println(found ? "Element found" : "Element not found");
}
}
Testcase:
Input: {10, 20, 30, 40, 50}, Search Key: 30
Output: Element found
5. Count Positive, Negative, and Zero ElementsImplementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM

MCA- Noon Batch : DIVISION :-- H


Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
6
2 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
public class CountNumbers {
public static void main(String[] args) {
int[] arr = {5, -3, 0, -2, 8, 0, 7};
int pos = 0, neg = 0, zero = 0;
for (int num : arr) {
if (num > 0) pos++;
else if (num < 0) neg++;
else zero++;
}
System.out.println("Positive: " + pos + ", Negative: " + neg + ", Zero: " +
zero);
}
}
TestCase:
Input: {5, -3, 0, -2, 8, 0, 7}
Output: Positive: 3, Negative: 2, Zero: 2

6. Copy Elements from One Array to Another


Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM
import java.util.Arrays;
public class CopyArray {
public static void main(String[] args) {
int[] arr1 = {1, 2, 3, 4, 5};
int[] arr2 = new int[arr1.length];
System.arraycopy(arr1, 0, arr2, 0, arr1.length);
System.out.println("Copied Array: " + Arrays.toString(arr2));
}
MCA- Noon Batch : DIVISION :-- H
Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
6
3 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
}
TestCase:
Input: {1, 2, 3, 4, 5}
Output: Copied Array: [1, 2, 3, 4, 5]

7. Sort an Array (Bubble Sort)


Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM
import java.util.Arrays;
public class BubbleSort {
public static void main(String[] args) {
int[] arr = {64, 34, 25, 12, 22, 11, 90};
for (int i = 0; i < arr.length - 1; i++) {
for (int j = 0; j < arr.length - i - 1; j++) {
if (arr[j] > arr[j + 1]) {
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
System.out.println("Sorted Array: " + Arrays.toString(arr));
}
}
TestCase:
Input: {64, 34, 25, 12, 22, 11, 90}
Output: Sorted Array: [11, 12, 22, 25, 34, 64, 90]

MCA- Noon Batch : DIVISION :-- H


Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
6
4 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
8. Merge Two Arrays
Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM
import java.util.Arrays;
public class MergeArrays {
public static void main(String[] args) {
int[] arr1 = {1, 3, 5};
int[] arr2 = {2, 4, 6};
int[] merged = new int[arr1.length + arr2.length];

System.arraycopy(arr1, 0, merged, 0, arr1.length);


System.arraycopy(arr2, 0, merged, arr1.length, arr2.length);
System.out.println("Merged Array: " + Arrays.toString(merged));
}
}
TestCase:
Input: {1, 3, 5} and {2, 4, 6}
Output: Merged Array: [1, 3, 5, 2, 4, 6]

10. Find Duplicate Elements


Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM

MCA- Noon Batch : DIVISION :-- H


Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
6
5 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
import java.util.HashSet;
public class FindDuplicates {
public static void main(String[] args) {
int[] arr = {1, 2, 3, 2, 4, 5, 1};
HashSet<Integer> seen = new HashSet<>();
System.out.print("Duplicates: ");
for (int num : arr) {
if (!seen.add(num)) {
System.out.print(num + " ");
}
}
}
}
TestCase:
Input: {1, 2, 3, 2, 4, 5, 1}
Output: Duplicates: 2 1
11. Frequency of Elements
Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM
import java.util.HashMap;
public class FrequencyCount {
public static void main(String[] args) {
int[] arr = {1, 2, 2, 3, 4, 4, 4, 5};
HashMap<Integer, Integer> freq = new HashMap<>();
for (int num : arr) {
freq.put(num, freq.getOrDefault(num, 0) + 1);
}
System.out.println("Frequency: " + freq);

MCA- Noon Batch : DIVISION :-- H


Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
6
6 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
}
}
TestCase:
Input: {1, 2, 2, 3, 4, 4, 4, 5}
Output: Frequency: {1=1, 2=2, 3=1, 4=3, 5=1}

12. Rotate an Array (Left Rotation)


Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM
import java.util.Arrays;
public class LeftRotateArray {
public static void main(String[] args) {
int[] arr = {1, 2, 3, 4, 5};
int first = arr[0];
for (int i = 0; i < arr.length - 1; i++) {
arr[i] = arr[i + 1];
}
arr[arr.length - 1] = first;
System.out.println("Rotated Array: " + Arrays.toString(arr));
}
}
TestCase:
Input: {1, 2, 3, 4, 5}
Output: Rotated Array: [2, 3, 4, 5, 1]

13. Second Largest Element in an Array


Implementation :
This program demonstrates input validation, code modularity,

MCA- Noon Batch : DIVISION :-- H


Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
6
7 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM
import java.util.Arrays;
public class SecondLargest {
public static void main(String[] args) {
int[] arr = {12, 35, 1, 10, 34, 1};
Arrays.sort(arr);
int secondLargest = arr[arr.length - 2];
System.out.println("Second Largest: " + secondLargest);
}
}
TestCase:
Input: {12, 35, 1, 10, 34, 1}
Output: Second Largest: 34

14. Check if an Array is Palindromic


Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM
public class PalindromicArray {
public static void main(String[] args) {
int[] arr = {1, 2, 3, 2, 1};
boolean isPalindrome = true;
MCA- Noon Batch : DIVISION :-- H
Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
6
8 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
for (int i = 0; i < arr.length / 2; i++) {
if (arr[i] != arr[arr.length - 1 - i]) {
isPalindrome = false;
break;
}
}
System.out.println(isPalindrome ? "Palindrome" : "Not Palindrome");
}
}
TestCase:
Input: {1, 2, 3, 2, 1}
Output: Palindrome

15. Insert an Element at a Specific Position


Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM
import java.util.Arrays;
public class InsertElement {
public static void main(String[] args) {
int[] arr = {1, 2, 4, 5};
int insertPos = 2, insertValue = 3;
int[] newArr = new int[arr.length + 1];

for (int i = 0, j = 0; i < newArr.length; i++) {


if (i == insertPos) newArr[i] = insertValue;
else newArr[i] = arr[j++];
}
System.out.println("Updated Array: " + Arrays.toString(newArr));

MCA- Noon Batch : DIVISION :-- H


Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
6
9 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
}
}
TestCase:
Input: {1, 2, 4, 5}, Position: 2, Value: 3
Output: Updated Array: [1, 2, 3, 4, 5]

16. Matrix Addition


Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM
public class MatrixAddition {
public static void main(String[] args) {
int[][] mat1 = {{1, 2}, {3, 4}};
int[][] mat2 = {{5, 6}, {7, 8}};
int[][] sum = new int[2][2];
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
sum[i][j] = mat1[i][j] + mat2[i][j];
}
}
System.out.println("Sum Matrix: ");
for (int[] row : sum) {
for (int val : row) {
System.out.print(val + " ");
}
System.out.println();
}
}
}

MCA- Noon Batch : DIVISION :-- H


Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
7
0 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
TestCase:
Input:
Matrix 1: [1, 2]
[3, 4]
Matrix 2: [5, 6]
[7, 8]
Output:
Sum Matrix: 6 8
10 12

17. Matrix Subtraction


Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM
public class MatrixSubtraction {
public static void main(String[] args) {
int[][] mat1 = {{9, 8}, {7, 6}};
int[][] mat2 = {{5, 4}, {3, 2}};
int[][] diff = new int[2][2];
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
diff[i][j] = mat1[i][j] - mat2[i][j];
}
} System.out.println("Difference Matrix: ");
for (int[] row : diff) {
for (int val : row) {
System.out.print(val + " ");
}
System.out.println();

MCA- Noon Batch : DIVISION :-- H


Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
7
1 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
}
}
}
TestCase:
Input:
Matrix 1: [9, 8]
[7, 6]
Matrix 2: [5, 4]
[3, 2]

Output :
Difference Matrix:
44
44
18. Transpose of a Matrix
Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 07:20 PM
public class TransposeMatrix {
public static void main(String[] args) {
int[][] mat = {{1, 2, 3}, {4, 5, 6}};
int rows = mat.length, cols = mat[0].length;
int[][] transposed = new int[cols][rows];
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
transposed[j][i] = mat[i][j];
}
}
System.out.println("Transpose:");

MCA- Noon Batch : DIVISION :-- H


Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
7
2 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
for (int[] row : transposed) {
for (int val : row) {
System.out.print(val + " ");
}
System.out.println();
}
}
}
TestCase:
Input:
Matrix: [1, 2, 3]
[4, 5, 6]
Output :
Transpose:
14
25
36

19. Multiply Two Matrices


Implementation :
This program demonstrates input validation, code modularity,
and testing by dividing the logic into multiple methods.
Problem: A program to print even number.
Roll No : 5
Enrolment Nos
:24004401110338
Author : Shruti Surve
Date of Creation:19/02/2025
Time of Creation : 10:20 AM
public class MatrixMultiplication {
public static void main(String[] args) {
int[][] mat1 = {{1, 2}, {3, 4}};
int[][] mat2 = {{5, 6}, {7, 8}};
int[][] result = new int[2][2];
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {

MCA- Noon Batch : DIVISION :-- H


Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve
7
3 LOK JAGRUTI KENDRA UNIVERSITY
School of Computer Application
Master of computer Application
Academic Year 2024-2025
Evening Batch – Division H
Assignments 0 : Basic Datatypes Control Statements Array and String
result[i][j] = mat1[i][0] * mat2[0][j] + mat1[i][1] * mat2[1][j];
}
}
System.out.println("Product Matrix:");
for (int[] row : result) {
for (int val : row) {
System.out.print(val + " ");
}
System.out.println();
}
}
}
TestCase:
Input:
Matrix 1: [1, 2]
[3, 4]
Matrix 2: [5, 6]
[7, 8]
Output :
Product Matrix:
19 22
43 50

MCA- Noon Batch : DIVISION :-- H


Roll No :-- 07
Enrollment No :-- 24004401110338
Name of the students :--Shruti Surve

You might also like