Function Solution
Function Solution
FUNCTIONS SOLUTIONS
[email protected]
Solution 1:
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Input the first number: ");
double x = sc.nextDouble();
System.out.print("Input the second number: ");
double y = sc.nextDouble();
System.out.print("Input the third number: ");
double z = sc.nextDouble();
System.out.print("The average value is " + average(x, y, z)+"\n" );
}
Solution 2:
import java.util.*;
if(isEven(num)) {
System.out.println("Number is even");
} else {
System.out.println("Number is odd");
}
}
[email protected]
public static boolean isEven(int number) {
if(number % 2 == 0) {
return true;
}
else {
return false;
}
}
}
Solution 3:
import java.util.Scanner;
if(isPalindrome(palindrome)) {
System.out.println("Number : " + palindrome + " is a palindrome");
} else {
System.out.println("Number : " + palindrome + " is not a palindrome");
}
}
public static boolean isPalindrome(int number) {
int palindrome = number; // copied number into variable
int reverse = 0;
while (palindrome != 0) {
int remainder = palindrome % 10;
reverse = reverse * 10 + remainder;
palindrome = palindrome / 10;
}
// if original and the reverse of number is equal means
// number is palindrome in Java
if (number == reverse) {
[email protected]
return true;
}
return false;
}
}
Solution 5:
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Input an integer: ");
int digits = sc.nextInt();
System.out.println("The sum is " + sumDigits(digits));
}
return sumOfDigits;
}
}