WriteamethodnamedisEventhatacceptsanintargument.Themethodshouldreturntrueiftheargumentiseven,orfalseotherwise.Alsowriteaprogramtotestyourmethod
public static boolean isEven(int n){
if(n%2==0){
return true;
}
return false;
}
public static void main(String[] args) {
System.out.println(isEven(9));
}
public static boolean isEven(int n){
if(n%2==0){
return true;
}
return false;
}
public static void main(String[] args) {
System.out.println(isEven(9));
}
public static int sum(int n){
int sum=0;
while(n>0){
int lastDigit = n%10;
sum= sum+lastDigit;
n=n/10;
}
return sum;
}
public static void main(String[] args) {
int n=78555;
int res=sum(n);
System.out.println(res);
}
Write a Java method to compute the sum of the digits in an integer.(Hint: Approach this question in the following way:a.Take a variable sum = 0b.Find the last digit of the numberc.Add it to the sumd.Repeat a & b until the number becomes 0 )
int sum=0;
while(n>0){
int lastDigit = n%10;
sum= sum+lastDigit;
n=n/10;
}
return sum;
}
public static void main(String[] args) {
int n=78555;
int res=sum(n);
System.out.println(res);
}
Write a Java method to compute the sum of the digits in an integer.(Hint: Approach this question in the following way:a.Take a variable sum = 0b.Find the last digit of the numberc.Add it to the sumd.Repeat a & b until the number becomes 0 )
❤1
Discussion about JAVA Programming
Screenshot 2024-03-14 180339.png
Today's Problem Solution.png
100.9 KB
Solution of this Problem 🎯