Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package chapterSix;
- import java.util.Scanner;
- public class Variousloops
- {
- public static void main(String[] args)
- {
- Scanner s = new Scanner(System.in);
- int OddsSum= 0;
- int n = 0;
- int amount = 0;
- System.out.println("Number:");
- n = s.nextInt();
- while ( n > 0 )
- {
- amount=n % 10;
- if ( n %2 == 1 )
- {
- OddsSum+=amount;
- }
- n/=10;
- }
- System.out.println(OddsSum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement