Advertisement
JoshJurban

Exercise 6.1E

Oct 23rd, 2014
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. package chapterSix;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Variousloops
  6. {
  7. public static void main(String[] args)
  8. {
  9. Scanner s = new Scanner(System.in);
  10.  
  11. int OddsSum= 0;
  12. int n = 0;
  13. int amount = 0;
  14.  
  15. System.out.println("Number:");
  16. n = s.nextInt();
  17.  
  18. while ( n > 0 )
  19. {
  20. amount=n % 10;
  21. if ( n %2 == 1 )
  22. {
  23. OddsSum+=amount;
  24. }
  25. n/=10;
  26. }
  27. System.out.println(OddsSum);
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement