VelizarAng

SumOfReversedNumbers

Apr 20th, 2021
790
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class SumReversedNums {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.         System.out.print("Enter the numbers: ");
  7.         String text = scan.nextLine();
  8.         String[] sptext = text.split(" ");
  9.         int sum = 0;
  10.  
  11.         for (int i = 0; i < sptext.length; i++) {
  12.             String currentEl = "";
  13.             for (int j = sptext[i].length() - 1; j >= 0; j--) {
  14.                 if(!String.valueOf(sptext[i].charAt(j)).equals("0")){
  15.                     currentEl += String.valueOf(sptext[i].charAt(j));
  16.                 }
  17.             }
  18.             sum += Integer.parseInt(currentEl);
  19.         }
  20.  
  21.         System.out.println("The sum of the reversed numbers: " + sum);
  22.     }
  23. }
  24.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×