Frage im Vorstellungsgespräch bei Nagarro

There were 2 Programs questions 1. Converting Java variable to cpp and vice versa e.g. if this_is_a_variable is CPP varaible and need to convert thisIsAVariable is java variable and if java variable is provided then need to convert into CPP (using any programming language)

Antworten zu Vorstellungsgespräch

Anonym

12. Sept. 2021

## JavaScript Solution /** * Convert Java Variable into CPP Variable * Example: * "this_is_a_variable" ------> "thisIsAVariable" */ function javaVariableToCPP(str){ let inputArr = str.split('_'); let arr = []; for(let char of inputArr){ arr.push(char.charAt(0).toUpperCase() + char.slice(1)); } return arr.join(''); } console.log(javaVariableToCPP("this_is_a_variable")); /** * Convert CPP Variable into Java Variable * Example: * "thisIsAVariable" ------> "this_is_a_variable" */ function cppVariableToJava(str){ let arr = []; for(let char of str){ if(char === char.toUpperCase()){ char = '_'+ char.charAt(0).toLowerCase() + char.slice(1); } arr.push(char); } return arr.join('') } console.log(cppVariableToJava("thisIsAVariable"));

2

Anonym

7. Sept. 2021

I used c# to implement it.