62582023-11-09 16:11:01RedStarDiana and NumbersjavaForditási hiba
import java.util.Scanner;

public class DianaAndNumbers {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        // Get the user input

        String numberAsString = sc.nextLine();


        while (true)
        {
            // If number has leading zeroes, remove them
            while (numberAsString.length() > 0 && numberAsString.charAt(0) == '0')
            {
                numberAsString = numberAsString.substring(1);
            }

            // If there is no number inside the variable, the user given number is impossible to make dividable by 3.
            if (numberAsString.length() == 0)
            {
                numberAsString = "-1";
                break;
            }


            // If number is dividable by 3, end the main cycle
            if (Long.parseLong(numberAsString) % 3 == 0)
            {
                break;
            }

            // Find the index of the first digit that's not dividable by 3.
            int index = -1;
            for (int i = 0; i < numberAsString.length(); i++)
            {
                if (numberAsString.charAt(i) % 3 != 0)
                {
                    index = i;
                    break;
                }

            }
            // Remove the digit from the whole number
            numberAsString = removeCharAt(numberAsString, index);

        }

        System.out.println(numberAsString);
    }

    public static String removeCharAt(String text, int index) {

        StringBuilder newString = new StringBuilder();

        for (int i = 0; i < text.length(); i++) {
            if (i != index) {
                newString.append(text.charAt(i));
            }
        }

        return newString.toString();
    }
}
Forditási hiba
exit status 1