Advertisement
Guest User

Untitled

a guest
Aug 14th, 2019
1,104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. import java.lang.reflect.Array;
  2. import java.util.*;
  3.  
  4. public class Main {
  5. public static void main(String[] args) {
  6. Scanner scan = new Scanner(System.in);
  7. String line = scan.nextLine();
  8. int counter =0;
  9. line = line.replace("-","");
  10. line = line.replace(".","");
  11. int [] array = new int[line.length()];
  12. for (int i = 0; i <array.length ; i++) {
  13. array[i]= Character.getNumericValue(line.charAt(i));
  14. }
  15. for (int j = 0; j <array.length ; j++) {
  16. counter = counter + array[j];
  17. if(counter>9){
  18. counter=counter/10+counter%10;
  19. }
  20. }
  21. System.out.println(counter);
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement