Java File
Java File
Ans-
class Name {
if (args.length > 0) {
else {
OUTPUT
Q-2 Write a program in java which enters three numbers using command line argument and print sum
and average of the number.
Ans-
class Main {
int a = Integer.parseInt(args[0]);
int b = Integer.parseInt(args[1]);
int c = Integer.parseInt(args[2]);
int sum = a + b + c;
}
OUTPUT
Q-3 Write a program to swap the value of 2 variable without using 3rd variable.
Ans-
class SwapWithoutThirdVariable {
int a = 10;
int b = 20;
a = a + b;
b = a – b;
a = a - b;
}
OUTPUT
Q-4 Write a program to calculate the sum of digits of given interger number.
Ans-
import java.util.Scanner;
class SumOfDigits {
int sum = 0;
number /= 10;
}
OUTPUT
Q-5 Write a program to compute the sum of the first and last digit of a given number.
Ans-
import java.util.Scanner;
class FirstAndLastDigitSum {
if (number < 0) {
return -1;
int a = number;
while (a >= 10) {
a /= 10;
return a + L;
if (result == -1) {
System.out.println("Invalid input.");
} else {
System.out.println("The sum of the first and last digit is: " + result);
sc.close();
}
OUTPUT
Q-6 Write a program in java which enter the number using data input stream and check whether the
entered number is even or odd.
Ans-
import java.io.DataInputStream;
import java.io.IOException;
class EvenOrOdd {
try {
n = Integer.parseInt(dis.readLine());
System.out.println("Invalid input.");
if (n % 2 == 0) {
} else {
}
OUTPUT
Q-7 Write an application that read a string and determine whether it is a palindrome.
Ans-
import java.util.Scanner;
class PalindromeChecker {
s = s.toLowerCase();
s = s.replaceAll("[^a-z0-9]", "");
int n = s.length();
return false;
}
return true;
if (isPalindrome(input)) {
} else {
sc.close();
OUTPUT
Q-8 Write a program to enter a sentence from keyboard and also find all the words in the sentence
with starting character as vowel.
Ans-
import java.util.Scanner;
class VowelWords {
System.out.println(word);
}
OUTPUT
Q-9 Write a program in java which creates the array of size 5. Find the sum and average of the five
numbers.
Ans-
class ArraySumAndAverage {
int sum = 0;
System.out.println();
}
OUTPUT
Q-10 Create a java that has three version of add method which can Add two, three and four integers.
Ans-
class Addition {
return a + b;
return a + b + c;
OUTPUT