Wipro TalentNext Java Full Stack
Java Fundamentals Hands-on Assignment-1
Date:22-07-2024
BY,Yehaasary KM-IIIrd yr AI&DS
Language Basics:
1) public class Location {
public static void main(String[] args) {
if ([Link] != 2) {
[Link](" pass two arguments ");
return;
}
String company = args[0];
String location = args[1];
[Link](company + " Technologies " + location);
}
}
2) public class Message {
public static void main(String[] args) {
if ([Link] != 1) {
[Link]("pass one argument ");
return;
}
String name = args[0];
[Link]("Welcome " + name);
}
}
3) public class Sum {
public static void main(String[] args) {
if ([Link] != 2) {
[Link](" pass two arguments");
return;
}
int num1 = [Link](args[0]);
int num2 = [Link](args[1]);
int sum = num1 + num2;
[Link]("The sum of " + num1 + " and " + num2 + " is " + sum);
}
}
Flow Control Statements:
1)A)
import [Link];
public class NumberCheck {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
[Link]("Enter an integer: ");
int number = [Link]();
if (number > 0) {
[Link]("The number is positive.");
} else if (number < 0) {
[Link]("The number is negative.");
} else {
[Link]("The number is zero.");
}
[Link]();
}
}
B)
public class LastDigit {
public static boolean lastDigit(int a, int b) {
return a % 10 == b % 10;
}
public static void main(String[] args) {
[Link](lastDigit(27, 57));
[Link](lastDigit(7, 17));
[Link](lastDigit(6, 17));
[Link](lastDigit(3, 113));
[Link](lastDigit(5, 115));
}
}
2) import [Link];
public class OddOrEven {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
[Link]("Enter an integer: ");
int number = [Link]();
if (isEven(number)) {
[Link]("The number is even.");
} else {
[Link]("The number is odd.");
}
[Link]();
}
public static boolean isEven(int number) {
return number % 2 == 0;
}
}
5) import [Link];
public class CharacterType {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
[Link]("Enter a character: ");
char character = [Link]().charAt(0);
if ([Link](character)) {
[Link]("Alphabet");
} else if ([Link](character)) {
[Link]("Digit");
} else {
[Link]("Special Character");
}
}
}
8) import [Link];
public class ColorCode {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
[Link]("Enter a color code: ");
String colorCode = [Link]();
switch (colorCode) {
case "R":
[Link]("Red");
break;
case "B":
[Link]("Blue");
break;
case "G":
[Link]("Green");
break;
case "O":
[Link]("Orange");
break;
case "Y":
[Link]("Yellow");
break;
case "W":
[Link]("White");
break;
default:
[Link]("Invalid Code");
}
}
}
11) public class EvenNumbers {
public static void main(String[] args) {
for (int i = 24; i <= 56; i += 2) {
[Link](i);
}
}
}
12) import [Link];
public class PrimeNumber {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
[Link]("Enter a number: ");
int num = [Link]();
boolean isPrime = true;
if (num <= 1) {
isPrime = false;
} else {
for (int i = 2; i <= [Link](num); i++) {
if (num % i == 0) {
isPrime = false;
break;
}
}
}
14) import [Link];
public class SumOfDigits {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
[Link]("Enter a number: ");
int number = [Link]();
int sum = 0;
while (number > 0) {
sum += number % 10;
number /= 10;
[Link]("Sum of digits: " + sum);
}
}
16) import [Link];
public class ReverseNumber {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
[Link]("Enter a number: ");
int number = [Link]();
int reversedNumber = 0;
while (number != 0) {
int digit = number % 10;
reversedNumber = reversedNumber * 10 + digit;
number /= 10;
}
[Link]("Reversed number: " + reversedNumber);
}
}
Arrays:
2) public class MinMax {
public static void main(String[] args) {
int[] numbers = {23, 45, 12, 78, 34, 89, 5, 56};
int max = findMax(numbers);
int min = findMin(numbers);
[Link]("The maximum value is: " + max);
[Link]("The minimum value is: " + min);
}
public static int findMax(int[] arr) {
int max = arr[0];
for (int i = 1; i < [Link]; i++) {
if (arr[i] > max) {
max = arr[i];
}
}
return max;
public static int findMin(int[] arr) {
int min = arr[0];
for (int i = 1; i < [Link]; i++) {
if (arr[i] < min) {
min = arr[i];
}
}
return min;
}
}
3)
import [Link];
public class ArraySearch {
public static void main(String[] args) {
int[] array = {1, 4, 34, 56, 7};
Scanner scanner = new Scanner([Link]);
[Link]("Enter the number to search: ");
int searchElement = [Link]();
int index = findIndex(array, searchElement);
[Link](index);
[Link]();
}
public static int findIndex(int[] array, int searchElement) {
for (int i = 0; i < [Link]; i++) {
if (array[i] == searchElement) {
return i;
}
}
return -1;
}
}
7) import [Link];
public class Duplicates {
public static void main(String[] args) {
int[] array = {12, 34, 12, 45, 67, 89};
int[] uniqueArray = removeDuplicates(array);
[Link]("Array after removing duplicates: " + [Link](uniqueArray));
}
public static int[] removeDuplicates(int[] array) {
int n = [Link];
[Link](array);
int[] temp = new int[n];
int j = 0;
for (int i = 0; i < n - 1; i++) {
if (array[i] != array[i + 1]) {
temp[j++] = array[i];
}
}
temp[j++] = array[n - 1];
int[] uniqueArray = new int[j];
for (int i = 0; i < j; i++) {
uniqueArray[i] = temp[i];
}
return uniqueArray;
}
}
10) import [Link];
public class Rearrange {
public static void main(String[] args) {
int[] array1 = {1, 0, 1, 0, 0, 1, 1};
int[] array2 = {3, 3, 2};
int[] array3 = {2, 2, 2};
[Link]("Rearranged array1: " + [Link](evenOdd(array1)));
[Link]("Rearranged array2: " + [Link](evenOdd(array2)));
[Link]("Rearranged array3: " + [Link](evenOdd(array3)));
}
public static int[] evenOdd(int[] array) {
int[] rearrangedArray = new int[[Link]];
int index = 0;
for (int num : array) {
if (num % 2 == 0) {
rearrangedArray[index++] = num;
}
}
for (int num : array) {
if (num % 2 != 0) {
rearrangedArray[index++] = num;
}
return rearrangedArray;
}
}
14) public class Array {
public static void main(String[] args) {
if ([Link] != 9) {
[Link]("Please enter 9 integer numbers");
return;
}
int[][] array = new int[3][3];
int index = 0;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
array[i][j] = [Link](args[index++]);
}
}
[Link]("The given array is:");
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
[Link](array[i][j] + " ");
}
[Link]();
int max = array[0][0];
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (array[i][j] > max) {
max = array[i][j];
}
}
}
[Link]("The biggest number in the given array is " + max);
}
}