Interview Question

Senior Java Developer Interview

-

Atlassian

A company uses a format to exchange messages with us. You need to validate the input. The character encoding ASCII. Valid characters are between 0x20 (space) and 0x7E (~). write validate function to generate valid output or the error message.

AnswerAdd Tags

Interview Answers

9 Answers

0

public static void printValidMassage(){ String msg="204a6176617e"; String msg1=convertHextoChars(msg); boolean isValid=(msg1.startsWith(" ") && msg1.endsWith("~")) ? true : false; } private static String convertHextoChars(String hex) { StringBuffer sb = new StringBuffer(); for (int i=0; i

Anonymous on

0

public static void printValidMassage(){ String msg="204a6176617e"; String msg1=convertHextoChars(msg); boolean isValid=(msg1.startsWith(" ") && msg1.endsWith("~")) ? true : false; System.out.println(isValid); } private static String convertHextoChars(String hex) { StringBuffer sb = new StringBuffer(); for (int i=0; i

Anonymous on

0

for (int i=0; i

Anonymous on

0

for (int i=0;i

Anonymous on

0

iterate by 2 chars and make parseInt with radix (16) and append in stringbuffer stringbuffer.append((char)Integer.parseInt(hex.substring(i,i+2),16));

Anonymous on

0

public static boolean validateMessage(String msg) { char[] chars = msg.toCharArray(); Arrays.sort(chars); if (chars[0] 0x7E) { return false; } return true; }

Anonymous on

0

Logical expression should be: if (chars[0] LESS THEN 0x7E OR chars[chars.length - 1] GREATER THEN 0x7E) {

Anonymous on

0

Correction: if (chars[0] LESS THEN 0x20 OR chars[chars.length - 1] GREATER THEN 0x7E) {

Anonymous on

0

public static void printValidMassage(){ String msg="204a6176617e"; String msg1=convertHextoChars(msg); boolean isValid=(msg1.startsWith(" ") && msg1.endsWith("~")) ? true : false; System.out.println(isValid); } private static String convertHextoChars(String hex) { StringBuffer sb = new StringBuffer(); for (int i=0; i

Anonymous on

Add Answers or Comments

To comment on this, Sign In or Sign Up.