Fragen im Vorstellungsgespräch bei Zalando: How to convert an Optional st... | Glassdoor.de

Frage im Vorstellungsgespräch

Senior Software Engineer-Vorstellungsgespräch Berlin

How to convert an Optional string to integer without

  throwing exception
Antwort

Antwort im Vorstellungsgespräch

4 Antworten

0

use filter and map

Bewerber im Vorstellungsgespräch am 19.01.2018
0

Well its pretty basic.
1. Convert String into character array.
2. Check if Array's length = 48 && intValue <= 57) {
                    int numValue = values[intValue - 48];
                    finalNumber += (numValue * Math.pow(10, power));
                    power--;
                } else {
                    System.out.println("Not a number");
                    return;
                }
            }
            finalNumber *= multiplier;
            System.out.println(finalNumber);
        }

Monis Yousuf am 05.12.2018
0

Program
___________________________________________

int[] values = {0,1,2,3,4,5,6,7,8,9};

        String test = "-123";
        char[] arr = test.toCharArray();
        if(arr.length = 48 && intValue <= 57) {
                    int numValue = values[intValue - 48];
                    finalNumber += (numValue * Math.pow(10, power));
                    power--;
                } else {
                    System.out.println("Not a number");
                    return;
                }
            }
            finalNumber *= multiplier;
            System.out.println(finalNumber);
        }

Monis Yousuf am 05.12.2018
0

glassdoor not allowing to post full code.

Anonym am 05.12.2018

Antwort oder Kommentar posten

Um dies zu kommentieren, bitte anmelden oder Konto anlegen.