Zalando Interview Question: How to convert an Optional st... | Glassdoor.co.in

Interview Question

Senior Software Engineer Interview Berlin (Germany)

How to convert an Optional string to integer without

  throwing exception
Answer

Interview Answer

4 Answers

0

use filter and map

Interview Candidate on 19-Jan-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 on 05-Dec-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 on 05-Dec-2018
0

glassdoor not allowing to post full code.

Anonymous on 05-Dec-2018

Add Answers or Comments

To comment on this, Sign In or Sign Up.