write a program to find given a maximum pf 100 digit numbers as input ,find the difference between the odd and even position digits
Answers
Answered by
2
Question:-
Write a program in Java to take a maximum of 100 numbers as input and find the difference between odd and even position digit.
Program:-
import java.util.*;
class Difference
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter 100 numbers..");
int even=0,odd=0;
for(int i=1;i<=100;i++)
{
if(i%2==1)
odd+=sc.nextInt();
else
even+=sc.nextInt();
}
System.out.println("Difference is: "+odd-even);
}
}
Similar questions