You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importjava.util.Arrays;
publicclassMain {
publicstaticvoidmain(String[] args) {
int[] nums = {1, 4, -3, 20, 7, 10};
inttemp;
for(inti = 0; i < nums.length; i++){
for (intj = i + 1; j < nums.length; j++){
temp = nums[i];
if(nums[i] < nums[j]){
temp = nums[i];
nums[i] = nums[j];
nums[j] = temp;
}
}
}
System.out.println("Our sorted array: " + Arrays.toString(nums));
System.out.println("Second largest number in the array: " + nums[1]);
}
}
Sum of the digits of the given number
publicclassMain {
publicstaticvoidmain(String[] args) {
intnum = 125;
intsum = 0;
intdigit;
while(num > 10){
digit = num % 10; // all digits before lastsum += digit;
num = num / 10;
}
digit = num; // last digitsum += digit;
System.out.println("Sum of the digits of the given number : " + sum);
}
}
Check if given number is divisible by 3 or 5 or 15 (FizzBuzz)