Advertisement
rushdie

Home exercises 1

Nov 21st, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. package Test;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class evenNum {
  6.  
  7. public static void main(String[] args) {
  8. // TODO Auto-generated method stub
  9. Scanner s = new Scanner(System.in);
  10. int location = 1, newNum = 0, x, temp;
  11.  
  12. System.out.println("Enter a number with at least 5 digits? ");
  13. x = s.nextInt();
  14. temp = x;
  15. // for(int i=1; i <= newNum; i++){
  16. while (temp > 0) {
  17. temp = temp % 2;
  18.  
  19. // if the number is divisible by 2 then it is even
  20. if (temp % 2 == 0) {
  21.  
  22. newNum = temp * location;
  23. location = location * 10;
  24. temp = temp % 10;
  25. }
  26. x = x / 10;
  27. temp = x;
  28.  
  29.  
  30. }
  31. System.out.println("The number is : " + newNum);
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement