Unity 3D Interview Question for Software Engineer / Developers


Country: United States
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.Arrays;
import java.util.List;

public class IPConvertToHex {


    public static void main(String[] args) {
        
        String ipHex = "";
        System.out.println(args[0]);
        
        List<String> ipAddress = Arrays.asList(args[0].split("\\.", 4));
        
        try{                      
            for (String s: ipAddress){
                s = String.format("%x", Integer.valueOf(s), 16);
                ipHex = ipHex + s;
            }
            System.out.println("0x"+ipHex);
        
        } catch (
                NullPointerException | 
                NumberFormatException | 
                UnsupportedOperationException e){
            
            System.out.println(e.getMessage() + "IP Address given is not supported.");
        }
    }
}

- Scott Miller December 05, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

package SimpleTools;

import java.util.Arrays;
import java.util.List;

public class IPConvertToHex {

    public static final String NOT_SUPPORTED = "IP format not supported.";
    
    public static void main(String[] args) {       
        System.out.println("You input: " + args[0]); 
        System.out.println(IPConvertToHex(args[0]));      
    }
    
    public static String IPConvertToHex(String s){          
        
        //VALIDATE INPUT
        List<String> octets = Arrays.asList(s.split("\\."));         
        if (octets.size() != 4){  
            return NOT_SUPPORTED;  
        }
        for (String o : octets) {
            try {
                if (!(0 <=  Integer.parseInt(o) && 256 > Integer.parseInt(o))){
                    return NOT_SUPPORTED;
                }               
            } catch (NumberFormatException | NullPointerException e){
                return NOT_SUPPORTED;
            }
        }       
        
        //BUILD HEX STRING
        StringBuilder hexIP = new StringBuilder();
        hexIP.append("0x");                        
        octets.forEach(octet -> {
            hexIP.append(String.format("%x", Integer.valueOf(octet), 16));               
        });
        
        //OUTPUT
        return hexIP.toString();
   
   }
}

- Smiller December 07, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class HexConversion {

public static void main(String args[]){

String hex = "";
String input = args[0];

List<String> inputAsList = new ArrayList<String>();
inputAsList = Arrays.asList(input.split("\\.", 4));

try{
for(String s:inputAsList){

int i = Integer.parseInt(s);
s = ""+Integer.toHexString(i);
hex = hex+s;

}
System.out.println(hex);
}

catch(NullPointerException|NumberFormatException e){

System.out.println(e.getMessage()+"IP address not supported");

}

}

}

- Anonymous September 04, 2018 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More