Advertisement
Droo

P4_1e

Oct 22nd, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.55 KB | None | 0 0
  1. package PreSession_05;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class p4_1e {
  6.  
  7.     public static void main(String[] args) {
  8.         // TODO Auto-generated method stub
  9.         Scanner sc=new Scanner(System.in);
  10.         int total=0;
  11.         System.out.println("Input a Number = ");
  12.         int num=sc.nextInt();
  13.         String number=Integer.toString(num);
  14.         for (int i=1;i<=number.length();i++)
  15.         {
  16.             int digit = number.charAt(i-1)-48;//because charAt(0) mean 1st digit & char 0=48;
  17.             if (digit%2==1)
  18.             {
  19.                 total=total+digit;
  20.             }
  21.            
  22.         }
  23.         System.out.println(total);
  24.     }
  25.  
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement