Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class test {
- public static void main(String[] args){
- @SuppressWarnings("resource")
- String str = new java.util.Scanner(System.in).next();
- int num = 0;
- for (int i = 0; i < str.length(); i++){
- int multiplier = i % 2 == 0 ? 1 : 3;
- num += Integer.parseInt(str.substring(i, i + 1)) * multiplier;
- }
- String numValidity = num % 10 == 0 ? "Your number is okay" : "Your number is invalid";
- System.out.printf("The 1-3-sum is %d.\n%s", num, numValidity);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement