Advertisement
Guest User

CardVerifier

a guest
Nov 12th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. public class CreditCardVerifier {
  2.  
  3. /**
  4. * @param args the command line arguments
  5. */
  6. static int i=1;
  7. public static void main(String[] args) {
  8. //declare decimal and quotient variables
  9. int q, dec;
  10. Scanner scanner = new Scanner(System.in);
  11. System.out.println("Enter a decimal number: ");
  12. dec = scanner.nextInt();
  13. int[] oct = Octal(dec);
  14.  
  15. int sum =0;
  16. for(int c=i-1;c>0;c--){
  17. System.out.print(oct[c]);
  18. int value= (int) oct[c];
  19. sum+=value;
  20. }
  21. // String sum1 = Integer.toString(sum);
  22. // System.out.println("Check the conveted sum: "+sum1);
  23. // while(sum1.length()>1){
  24. //
  25. // sum=
  26. // }
  27. System.out.println("The sum is: "+sum);
  28. }
  29. static int[] Octal(int q){
  30.  
  31. //create an integer array to store the remainder
  32. int[] a = new int[50];
  33. while(q != 0){
  34.  
  35. a[i++] = q%8;
  36. q=q/8;
  37. }
  38. return a;
  39. }
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement