Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package PreSession_05;
- import java.util.Scanner;
- public class p4_1e {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Scanner sc=new Scanner(System.in);
- int total=0;
- System.out.println("Input a Number = ");
- int num=sc.nextInt();
- String number=Integer.toString(num);
- for (int i=1;i<=number.length();i++)
- {
- int digit = number.charAt(i-1)-48;//because charAt(0) mean 1st digit & char 0=48;
- if (digit%2==1)
- {
- total=total+digit;
- }
- }
- System.out.println(total);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement