Aditya Termwork
Aditya Termwork
CODE:
import
java.util.Scanner; public
class SeriesSum{
Scanner(System.in);
double x = scanner.nextDouble();
double y = scanner.nextDouble();
int n = scanner.nextInt();
{ double sum = 0;
int exponentX = 2 * i + 1;
int exponentY = 2 * (i +
1);
return sum;
}
NAME: ADITYA SURI UNIVERSITY ROLL NO: 2102586 COURSE: BCA
OUTPUT:
NAME: ADITYA SURI UNIVERSITY ROLL NO: 2102586 COURSE: BCA
2. WAP in Java to initialize 2D integer array of type uneven in order to print average
of each row. Array should be initialized by the user.
CODE:
import java.util.Scanner;
unevenArray[i][j] = scanner.nextInt();
System.out.println("Input array:");
printArray(unevenArray)
System.out.println("Average of each
row:");
calculateAndPrintAverage(unevenArray);
System.out.println();
int sum = 0;
{ sum += arr[i][j];
}
NAME: ADITYA SURI UNIVERSITY ROLL NO: 2102586 COURSE: BCA
OUTPUT:
NAME: ADITYA SURI UNIVERSITY ROLL NO: 2102586 COURSE: BCA
CODE:
import
java.text.DecimalFormat; class
Circle {
{ this.radius = radius;
class Rectangle {
private double
length; private
double width;
{ this.length = length;
this.width = width;
7);
formatArea(rectangleArea));
DecimalFormat df = new
}
NAME: ADITYA SURI UNIVERSITY ROLL NO: 2102586 COURSE: BCA
OUTPUT:
NAME: ADITYA SURI UNIVERSITY ROLL NO: 2102586 COURSE: BCA
4. WAP to use of super keyword to access variable, method and constructor calling.
CODE:
class Superclass
{ int number;
Superclass(int number)
{ this.number =
number;
void display() {
void display() {
number);
void accessSuperclassVariable() {
}
NAME: ADITYA SURI UNIVERSITY ROLL NO: 2102586 COURSE: BCA
}
NAME: ADITYA SURI UNIVERSITY ROLL NO: 2102586 COURSE: BCA
20); subclassObj.display();
subclassObj.accessSuperclassVariable();
}
NAME: ADITYA SURI UNIVERSITY ROLL NO: 2102586 COURSE: BCA
OUTPUT:
NAME: ADITYA SURI UNIVERSITY ROLL NO: 2102586 COURSE: BCA
5. WAP to implement the upcasting and down-casting between parent and child class.
CODE:
class Parent {
void parentMethod() {
System.out.println("This is a method of Parent class.");
}
}
OUTPUT:
NAME: ADITYA SURI UNIVERSITY ROLL NO: 2102586 COURSE: BCA
CODE:
import
java.io.FileNotFoundException;
import java.io.IOException;
try {
openFile("nonExistentFile.txt");
} catch (FileNotFoundException e) {
System.out.println("FileNotFoundException: " +
e.getMessage());
} catch (IOException e) {
System.out.println("IOException: " + e.getMessage());
}
}
OUTPUT:
NAME: ADITYA SURI UNIVERSITY ROLL NO: 2102586 COURSE: BCA
CODE:
import
java.util.Scanner; public
class WAP {
public static void main(String[] args) {
Scanner(System.in);
System.out.println("Enter
Name:"); String name =
scanner.nextLine();
System.out.println("Enter
City:"); String city =
scanner.nextLine();
System.out.println("Enter
Age:"); int age =
scanner.nextInt();
System.out.println("Enter Gender
(M/F):"); char gender =
scanner.next().charAt(0);
NAME: ADITYA SURI UNIVERSITY ROLL NO: 2102586 COURSE: BCA
}
public static String generateWiFiPassword(String name, String city, int age, char gender)
{ String password = "";
NAME: ADITYA SURI UNIVERSITY ROLL NO: 2102586 COURSE: BCA
password += name.substring(0,
3).toUpperCase(); password += city.substring(0,
3).toUpperCase(); password +=
String.valueOf(age).substring(0, 2); password +=
gender;
return password;
}
}
NAME: ADITYA SURI UNIVERSITY ROLL NO: 2102586 COURSE: BCA
OUTPUT:
NAME: ADITYA SURI UNIVERSITY ROLL NO: 2102586 COURSE: BCA
8. WAP in Java to take input (more than one) using command line and compare it with
input taken using Scanner. If there is any match, print “Character Found” else throw
a NoMatchException (also message).
CODE:
import
java.util.Scanner; public
class WAP {
if (args.length > 0) {
for (String arg : args)
{ userInput += arg + "
";
}
} else {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter multiple inputs (separated by space):
"); userInput = scanner.nextLine();
}
E"; try {
compareInputs(userInput, inputFromCommandLine);
} catch (NoMatchException e) {
System.out.println(e.getMessage())
;
}
}
if (!matchFound) {
throw new NoMatchException("No matching characters found in command line input.");
}
}
}
OUTPUT:
NAME: ADITYA SURI UNIVERSITY ROLL NO: 2102586 COURSE: BCA
9. WAP in Java to initialize two string and find common characters and different
Characters of these string.
CODE:
import
java.util.Scanner; public
class WAP {
public static void main(String[] args) {
Scanner scanner = new
Scanner(System.in);
System.out.println("Enter first string: ");
String str1 = scanner.nextLine();
System.out.println("Enter second string: ");
String str2 = scanner.nextLine();
compareStrings(str1, str2);
}
OUTPUT:
NAME: ADITYA SURI UNIVERSITY ROLL NO: 2102586 COURSE: BCA
10. WAP in Java to initialize a string in order to find that character which frequency is
2nd most in that string.
CODE:
import java.util.*;
if (maxCountCharList.size() < 2) {
System.out.println("2nd most frequent character not
found."); return;
}
NAME: ADITYA SURI UNIVERSITY ROLL NO: 2102586 COURSE: BCA
OUTPUT:
NAME: ADITYA SURI UNIVERSITY ROLL NO: 2102586 COURSE: BCA
11. WAP to find the average of second minimum and second highest number from the
array?
CODE:
import
java.util.Arrays;
OUTPUT:
NAME: ADITYA SURI UNIVERSITY ROLL NO: 2102586 COURSE: BCA
a=2 CODE:
import
java.util.HashMap;
import java.util.Map;
if (map.containsKey(c)) {
map.put(c, map.get(c) + 1);
} else {
map.put(c, 1);
}
map.clear();
map.put(maxChar, maxLength);
return map;
}
}
NAME: ADITYA SURI UNIVERSITY ROLL NO: 2102586 COURSE: BCA
OUTPUT;
NAME: ADITYA SURI UNIVERSITY ROLL NO: 2102586 COURSE: BCA
CODE:
import java.util.*;
while (iterator.hasNext()) {
System.out.println(iterator.next())
;
}
}
}
NAME: ADITYA SURI UNIVERSITY ROLL NO: 2102586 COURSE: BCA
OUTPUT:
NAME: ADITYA SURI UNIVERSITY ROLL NO: 2102586 COURSE: BCA
14. WAP to enter string through command line argument that may contain numeric or
alphanumeric. You have to sum out all numeric digit as well as create a string from
remaining characters in order to find your name can be created from that string or
not.
CODE:
{ if (args.length != 1) {
System.out.println("Please enter a string through command line argument.");
return;
}
String inputString =
args[0]; String
remainingChars = ""; int
sumOfDigits = 0;
if (Character.isDigit(currentChar)) {
sumOfDigits += Character.getNumericValue(currentChar);
} else {
remainingChars += currentChar;
}
}
}
}
NAME: ADITYA SURI UNIVERSITY ROLL NO: 2102586 COURSE: BCA
OUTPUT:
NAME: ADITYA SURI UNIVERSITY ROLL NO: 2102586 COURSE: BCA
15. WAP to find number of ‘a’ in a string s=” alialiali” without using charAt() method.
CODE:
{ String s = "alialiali";
int count = 0;
char[] chars =
chars) {
if (c == 'a')
{ count+
+;
}
}
OUTPUT:
NAME: ADITYA SURI UNIVERSITY ROLL NO: 2102586 COURSE: BCA
CODE:
import
java.util.Scanner; public
class Main {
public static void main(String[] args) {
Scanner scanner = new
Scanner(System.in);
OUTPUT: