Keshav_Java
Keshav_Java
1. Write a program in java which prints your name using command line arguments.
if (args.length > 0) {
System.out.println(args[0]);
}
PRACTICAL - 02
2. Write a program in java which enters three number using command line arguments and print
average of the number
if (args.length == 3) {
System.out.println(average);
}
PRACTICAL - 03
3. Write a program to swap the value of 2 variables without using 3rd variable
}
PRACTICAL - 04
4. Write a program to calculate the sum of digits of a given integer no
import java.util.Scanner;
int sum = 0;
while (new_nums != 0) {
new_nums /= 10;
System.out.println(sum);
}
PRACTICAL - 05
5. Write a program to compute the sum of the first and last digit of a given number.
import java.util.Scanner;
nums /= 10;
System.out.println(first + last);
}
PRACTICAL - 06
6. Write a program in java which enter the number using Data Input Stream and check entered
number is even or odd.
import java.io.DataInputStream;
if (number % 2 == 0) {
System.out.println("Even");
} else {
System.out.println("Odd");
}
PRACTICAL - 07
7. Write an application that reads a string and determines whether it is a palindrome.
import java.util.Scanner;
if (str_name.equals(reversed_str)) {
System.out.println("Palindrome");
} else {
System.out.println("Not a Palindrome");
}
PRACTICAL - 08
8. Write a program to enter a sentence form keyboard and also find all the words in that sent
starting character as vowel
import java.util.Scanner;
System.out.println(isword);
}
PRACTICAL - 09
9. Write a Program in java which creates the array of size 5; find the sum and average o numbers.
import java.util.Scanner;
int sum = 0;
nums[i] = sc.nextInt();
sum += nums[i];
}
PRACTICAL - 10
10. Create a java program that has three version of add method which can add two, three,
integers.
System.out.println(obj.add(4, 16));
System.out.println(obj.add(2,7,9));
}
PRACTICAL - 11
11. Program illustrating Classes and Objects.
class Pirate {
String Pirate_name;
int bounty;
void display() {
New_gen.bounty = 320;
s1.display();
}
PRACTICAL - 12
12. Program illustrating Method Overloading and Method Overriding.
class Animal {
void sound() {
System.out.println("Animal makes a sound");
}
}
class Cat extends Animal {
@Override
void sound() {
System.out.println("Cat Meows");
}
void sound(String type) {
System.out.println("Cat " + type + "s");
}
public static void main(String[] args) {
Animal a = new Animal();
a.sound();
Cat c = new Cat();
c.sound();
c.sound("meow meow");
}
}
PRACTICAL - 13
13. Program illustrating concept of Interface.
interface Anime {
void Anime_name();
System.out.println("Demon Slayer");
New_name.Anime_name();
}
PRACTICAL - 14
14. Program illustrating use of Final and Super keyword.
class Parent {
void display() {
System.out.println("Parent class");
void display() {
super.display();
System.out.println("Child class");
New_obj.display();
}
PRACTICAL - 15
15. Program that illustrates the Creation of simple package.
package mypackage;
}
PRACTICAL - 16
16. Program that illustrates the Accessing of a package.
import mypackage.HelloWorld;
new_name.anime_name();
}
PRACTICAL - 17
17. Program that illustrates the Handling of predefined exceptions.
import java.util.Scanner;
try {
System.out.println(first / second);
} catch (ArithmeticException e) {
}
PRACTICAL - 18
18. Program that illustrates the Handling of user defined exceptions.
super(message);
try {
if (!name.equals("Berserk")) {
catch (InvalidAnimeException e) {
System.out.println(e.getMessage());