Write a program in java to find out whether a number has the sum of its even and odd digits the same.
Answers
Answered by
0
Another method to check odd or even, for explanation see: C program to check odd or even. Code:
import java.util.Scanner;
class EvenOdd
{
public static void main(String args[])
{
int c;
System.out.println("Input an integer");
Scanner in = new Scanner(System.in);
c = in.nextInt();
if ( (c/2)*2 == c )
System.out.println("Even");
else
System.out.println("Odd");
}
}
import java.util.Scanner;
class EvenOdd
{
public static void main(String args[])
{
int c;
System.out.println("Input an integer");
Scanner in = new Scanner(System.in);
c = in.nextInt();
if ( (c/2)*2 == c )
System.out.println("Even");
else
System.out.println("Odd");
}
}
Anonymous:
I asked whether the sum of even and odd digits is same.
Answered by
1
HERE IS A JAVA PROGRAM
_________________________________________
import java.util.
Scanner;
public
class
Sum_Odd_Even
{
public
static
void main
(String[] args)
{
int n, sumE = 0, sumO = 0; Scanner s = new Scanner(System.in);
System.out.print("Enter the number of elements in array:"); n = s.nextInt(); int[] a = new int[n];
System.out.println
("Enter the elements of the array:"); for(int i = 0; i < n; i++) { a[i] = s.nextInt();
}
for(int i = 0; i < n; i++) { if(a[i] % 2 == 0) { sumE = sumE + a[i]; }
else
{
sumO = sumO + a[i]; } } System.out.println("Sum of Even Numbers:"+sumE)
; System.out.println("Sum of Odd Numbers:"+sumO);
}
}
_________________________________________
import java.util.
Scanner;
public
class
Sum_Odd_Even
{
public
static
void main
(String[] args)
{
int n, sumE = 0, sumO = 0; Scanner s = new Scanner(System.in);
System.out.print("Enter the number of elements in array:"); n = s.nextInt(); int[] a = new int[n];
System.out.println
("Enter the elements of the array:"); for(int i = 0; i < n; i++) { a[i] = s.nextInt();
}
for(int i = 0; i < n; i++) { if(a[i] % 2 == 0) { sumE = sumE + a[i]; }
else
{
sumO = sumO + a[i]; } } System.out.println("Sum of Even Numbers:"+sumE)
; System.out.println("Sum of Odd Numbers:"+sumO);
}
}
Similar questions
English,
7 months ago
English,
7 months ago
Math,
1 year ago
Geography,
1 year ago
Social Sciences,
1 year ago