Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class SumOfBackwardNumbers {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- System.out.println("Input numbers: ");
- String text = scan.nextLine();
- String[] SplitText = text.split(" ");
- int sum = 0;
- for (int i = 0; i < SplitText.length; i++) {
- String CurrentELement = "";
- for (int j = SplitText[i].length() - 1; j >= 0; j--) {
- if(!String.valueOf(SplitText[i].charAt(j)).equals("0")){
- CurrentELement += String.valueOf(SplitText[i].charAt(j));
- }
- }
- int curEl = Integer.parseInt(CurrentELement);
- sum += curEl;
- System.out.print(curEl + " + ");
- }
- System.out.print("0");
- System.out.println(" = " + sum);
- }
- }
Add Comment
Please, Sign In to add comment