Advertisement
TehVulpes

Pretty-printed 1-3-sum

Feb 23rd, 2013
34
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 test {
  2.     public static void main(String[] args){
  3.         @SuppressWarnings("resource")
  4.         String str = new java.util.Scanner(System.in).next();
  5.         int num = 0;
  6.  
  7.         for (int i = 0; i < str.length(); i++){
  8.             int multiplier = i % 2 == 0 ? 1 : 3;
  9.             num += Integer.parseInt(str.substring(i, i + 1)) * multiplier;
  10.         }
  11.  
  12.         String numValidity = num % 10 == 0 ? "Your number is okay" : "Your number is invalid";
  13.         System.out.printf("The 1-3-sum is %d.\n%s", num, numValidity);
  14.     }
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement