Advertisement
Maksud3

part5

Nov 26th, 2020
661
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.46 KB | None | 0 0
  1. package com.epam.rd.java.basic.practice1;
  2.  
  3. public class Part5 {
  4.  
  5.     public static void main(String[] args) {
  6.         int sum = 0;
  7.         try {
  8.             int number = Integer.parseInt(args[0]);
  9.             if (number > 0) {
  10.                 for (char digit : args[0].toCharArray()) {
  11.                     sum += digit - 48;
  12.                 }
  13.             }
  14.         } catch (NumberFormatException ignored) {
  15.         }
  16.         System.out.println(sum);
  17.     }
  18. }
  19.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement