micher43

E6.1 part E

Oct 23rd, 2014
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.48 KB | None | 0 0
  1. public class E61 {
  2.  
  3.     public static void main(String[] args) {
  4.        
  5.            
  6.         String num = "398898546948";
  7.         char digit = ' ';
  8.         int readableDigit;
  9.         int SumOddDigits=0;
  10.         int index = 0;
  11.        
  12.         for(index = 0; index < num.length(); index++)
  13.         {
  14.             digit = num.charAt(index);
  15.            
  16.             readableDigit = Character.getNumericValue(digit);
  17.        
  18.             if(readableDigit % 2 != 0)
  19.             {          
  20.             SumOddDigits = SumOddDigits + readableDigit;
  21.             }
  22.         }
  23.         System.out.println(SumOddDigits);
  24.     }
  25.  
  26. }
Advertisement
Add Comment
Please, Sign In to add comment