0% found this document useful (0 votes)
21 views5 pages

21BCS11408_Arpit Anand(JAVA Day2)

Fybvhnm

Uploaded by

Arpit Anand
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views5 pages

21BCS11408_Arpit Anand(JAVA Day2)

Fybvhnm

Uploaded by

Arpit Anand
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

Winning Camp Worksheet


DAY 2

Student Name: Arpit Anand UID: 21BCS11408


Branch: CSE Section/Group:21BCS_FL-604-B
Semester: 6th Date of Performance: 27-05-2024
Subject: Advanced Java

1. Objective: Topic Covered: Access Modifiers, Packages, Wrapper classes,


Boxing and Unboxing

Problem 1: A palindrome is a word, phrase, number, or other sequence of characters


which reads the same backward or forward.
Given a string A, print Yes if it is a palindrome, print No otherwise.

Problem 2: Write a function that accepts two parameters and finds whether the first
parameter is an exact multiple of the second parameter. If the first parameter is an exact
multiple of the second parameter, the function should return 2 else it should return 1. If
either of the parameters are zero, the function should return 3.

Problem 3: Given an integer array nums, move all 0's to the end of it while maintaining
the relative order of the non-zero elements.

Problem 4: You are given a 0-indexed array of integers nums of length n. You are
initially positioned at nums[0].
Each element nums[i] represents the maximum length of a forward jump from index i. In
other words, if you are at nums[i], you can jump to any nums[i + j] where:
0 <= j <= nums[i] and
i+j<n
Return the minimum number of jumps to reach nums[n - 1]. The test cases are generated
such that you can reach nums[n - 1].
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

2. Code:
Problem 1:
public class Solution {

public static void main(String[] args) {


Scanner sc=new Scanner(System.in);
String A=sc.next();
/* Enter your code here. Print output to STDOUT. */

int size = 0;
int length = A.length();
boolean result=true;
char[] charArr = A.toCharArray();

if (length%2==0) {
size = length/2-1;
} else {
size = length/2;
}

int y=length-1;

for (int i=0; i<=size; i++) {


if(charArr[i] != charArr[y]) {
result = false;
break;
}
y--;
}

if (result) System.out.println("Yes");

else System.out.println("No");
}
}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

Problem 2:
class UserMainCode{
public int isMultiple(int input1, int input2){
if(input1==0||input2==0){
return 3;
}else if(input1%input2==0){
return 2;
}else{
return 1;
}
}
}

Problem 3:
class Solution {
public void moveZeroes(int[] nums) {
int snowBallSize = 0;
for (int i=0;i<nums.length;i++){
if (nums[i]==0){
snowBallSize++;
}
else if (snowBallSize > 0) {
int t = nums[i];
nums[i]=0;
nums[i-snowBallSize]=t;
}
}
}
}

Problem 4:
class Solution {
int ans = 0;

public int jump(int[] nums) {


int i = 0;
while (i < nums.length - 1) {
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

i = helper(i, nums[i], nums);

}
return ans;
}

public int helper(int a, int b, int[] nums) {


ans++;
if (a + b >= nums.length - 1) {
return nums.length;
}
int max = Integer.MIN_VALUE;
int temp = 0;
for (int i = a; i <= a + b; i++) {
if (nums[i] + i >= max) {
temp = i;
max = nums[i] + i;
}
}
return temp;
}
}

OUTPUT:
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

You might also like