21BCS11408_Arpit Anand(JAVA Day2)
21BCS11408_Arpit Anand(JAVA Day2)
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 {
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;
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;
}
return ans;
}
OUTPUT:
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING