IBM Interview Question
Software Engineer / DevelopersCountry: United States
No, Abhinav, it is not.It is called ZoomBA.
You can take it as a certain pseudo lang if you wish too.
You can read more about it here : gitlab.com/non.est.sacra/zoomba
Albeit, is a declarative fully functional language on its own.
public class ReverseToString {
public static void main(String[] args) {
String inp = "How Are You Doing Today";
boolean firstWord = false;
for (int i = inp.length() - 1; i >= 0; i--) {
if (firstWord == false) {
System.out.print(String.valueOf(inp.charAt(i)).toUpperCase());
firstWord = true;
} else if (String.valueOf(inp.charAt(i)).equals(" ")) {
System.out.print(" "
+ String.valueOf(inp.charAt(i - 1)).toUpperCase());
i = i - 1;
} else {
System.out.print(String.valueOf(inp.charAt(i)).toLowerCase());
}
}
}
}
In C#
private static void ReverseString(string sentence)
{
if (sentence.Contains(" "))
{
char[] seperator = { ' ' };
string[] words = sentence.Split(seperator);
string[] reversedWords = new string[10];
int increment = 0;
foreach (string word in words)
{
string reverdedword = new string(word.Reverse().ToArray());
reversedWords[increment] = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(reverdedword);
increment++;
}
string[] weversedColletion = reversedWords.Reverse().ToArray();
Console.Write(string.Join(" ",weversedColletion));
}
}
private static void ReverseString(string sentence)
{
if (sentence.Contains(" "))
{
char[] seperator = { ' ' };
string[] words = sentence.Split(seperator);
string[] reversedWords = new string[10];
int increment = 0;
foreach (string word in words)
{
string reverdedword = new string(word.Reverse().ToArray());
reversedWords[increment] = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(reverdedword);
increment++;
}
string[] weversedColletion = reversedWords.Reverse().ToArray();
Console.Write(string.Join(" ",weversedColletion));
}
}
public class ReverseString {
public static void main(String[] args) {
String input1 = "Hello World";
String input2 = "How is the weather today !";
System.out.println(reverseString(input1));
System.out.println(reverseString(input2));
}
private static StringBuilder reverseString(String input) {
StringBuilder result = new StringBuilder();
String[] words = input.split(" ");
for(int i=(words.length - 1); i>=0; i--) {
for(int j=(words[i].length() - 1); j>=0; j--) {
if( j == (words[i].length() - 1))
result.append(String.valueOf(words[i].charAt(j)).toUpperCase());
else if( j == 0)
result.append(String.valueOf(words[i].charAt(j)).toLowerCase());
else
result.append(String.valueOf(words[i].charAt(j)));
}
if(i!=0)
result.append(" ");
}
return result;
}
}
namespace String
{
static class StringWorkAround
{
public static string stringreverser(string s)
{
char[] array1 = s.ToCharArray();
Array.Reverse(array1);
//to lower all chars
for (int K = 1; K < array1.Length; K++)
{
array1[K] = char.ToLower(array1[K]);
}
if (array1.Length >= 1)
{
array1[0] = char.ToUpper(array1[0]);
}
// Scan through the letters, checking for spaces.
// ... Uppercase the lowercase letters following spaces.
for (int K = 1; K < array1.Length; K++)
{
if (array1[K - 1] == ' ')
{
array1[K] = char.ToUpper(array1[K]);
}
}
return new string(array1);
}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine(StringWorkAround.stringreverser("Hello World"));
//Console.WriteLine(StringWorkAround.stringreverser("Happy New Year"));
Console.WriteLine(StringWorkAround.stringreverser("How Are YOu Doing Today"));
}
}
}
namespace String
{
static class StringWorkAround
{
public static string stringreverser(string s)
{
char[] array1 = s.ToCharArray();
Array.Reverse(array1);
//to lower all chars
for (int K = 1; K < array1.Length; K++)
{
array1[K] = char.ToLower(array1[K]);
}
if (array1.Length >= 1)
{
array1[0] = char.ToUpper(array1[0]);
}
// Scan through the letters, checking for spaces.
// ... Uppercase the lowercase letters following spaces.
for (int K = 1; K < array1.Length; K++)
{
if (array1[K - 1] == ' ')
{
array1[K] = char.ToUpper(array1[K]);
}
}
return new string(array1);
}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine(StringWorkAround.stringreverser("Hello World"));
//Console.WriteLine(StringWorkAround.stringreverser("Happy New Year"));
Console.WriteLine(StringWorkAround.stringreverser("How Are YOu Doing Today"));
}
}
}
namespace String
{
static class StringWorkAround
{
public static string stringreverser(string s)
{
char[] array1 = s.ToCharArray();
Array.Reverse(array1);
//to lower all chars
for (int K = 1; K < array1.Length; K++)
{
array1[K] = char.ToLower(array1[K]);
}
if (array1.Length >= 1)
{
array1[0] = char.ToUpper(array1[0]);
}
// Scan through the letters, checking for spaces.
// ... Uppercase the lowercase letters following spaces.
for (int K = 1; K < array1.Length; K++)
{
if (array1[K - 1] == ' ')
{
array1[K] = char.ToUpper(array1[K]);
}
}
return new string(array1);
}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine(StringWorkAround.stringreverser("Hello World"));
//Console.WriteLine(StringWorkAround.stringreverser("Happy New Year"));
Console.WriteLine(StringWorkAround.stringreverser("How Are YOu Doing Today"));
}
}
}
public class Reverse_string
{
public static void main(String args[])
{
String original, reverse="";
Scanner in=new Scanner(System.in);
System.out.println("Enter the reverse string:");
original=in.nextLine();
int length=original.length();
for(int i=length-1; i>=0; i--)
{
reverse=reverse+original.charAt(i);
}
System.out.println("Reversed string is:" +reverse);
}
}
public class Reverse_string
{
public static void main(String args[])
{
String original, reverse="";
Scanner in=new Scanner(System.in);
System.out.println("Enter the reverse string:");
original=in.nextLine();
int length=original.length();
for(int i=length-1; i>=0; i--)
{
reverse=reverse+original.charAt(i);
}
System.out.println("Reversed string is:" +reverse);
}
}
import java.util.Scanner;
public class Reversal_2 {
public static void main(String[] args) {
System.out.println("enter the sentence");
Scanner s = new Scanner(System.in);
String input = s.nextLine();
input = input.toLowerCase();
String reversed = recursive(input);
char[] array = reversed.toCharArray();
int len = reversed.length();
array[0] = Character.toUpperCase(array[0]);
System.out.print(array[0]);
for (int i = 1; i < len; i++) {
if (array[i] == ' ')
array[i + 1] = Character.toUpperCase(array[i + 1]);
System.out.print(array[i]);
}
}
private static String recursive(String input) {
if (input.length() <= 1 || input == null)
return input;
return recursive(input.substring(1)) + input.charAt(0);
}
}
public class reverseString {
public static void main(String[] args) {
String first = "How Are You Doing Today";
System.out.println(reverse(first));
}
private static String reverse(String first) {
StringBuilder test = new StringBuilder();
boolean space = false;
test.append(Character.toUpperCase(first.charAt(first.length() - 1)));
for (int i = first.length() - 2; i >= 0; i--) {
if (Character.isUpperCase(first.charAt(i))) {
test.append(Character.toLowerCase(first.charAt(i)));
space = false;
} else if (first.charAt(i) == ' ') {
space = true;
test.append(first.charAt(i));
} else if (space) {
test.append(Character.toUpperCase(first.charAt(i)));
space = false;
} else {
space = false;
test.append(first.charAt(i));
}
}
return test.toString();
}
}
public class reverseString {
public static void main(String[] args) {
String first = "How Are You Doing Today";
System.out.println(reverse(first));
}
private static String reverse(String first) {
StringBuilder test = new StringBuilder();
boolean space = false;
test.append(Character.toUpperCase(first.charAt(first.length() - 1)));
for (int i = first.length() - 2; i >= 0; i--) {
if (Character.isUpperCase(first.charAt(i))) {
test.append(Character.toLowerCase(first.charAt(i)));
space = false;
} else if (first.charAt(i) == ' ') {
space = true;
test.append(first.charAt(i));
} else if (space) {
test.append(Character.toUpperCase(first.charAt(i)));
space = false;
} else {
space = false;
test.append(first.charAt(i));
}
}
return test.toString();
}
}
public String reverseWordsInString(String s){
if(s == null || s.length() == 0 || s.trim().length() == 0){
return s;
}
String[] words = s.split(" ");
String[] revWords = new String[words.length];
for(int i=0; i<words.length;i++){
String word = words[i].trim();
char[] revW = reverseWord(word);
revWords[i] = new String(revW);
}
StringBuilder builder = new StringBuilder();
for(int i=revWords.length-1;i>=0;i--){
builder.append(revWords[i]).append(" ");
}
return builder.toString();
}
private char[] reverseWord(String word){
int j = word.length()-1;
int k =0;
char[] rWord = new char[word.length()];
char[] wordA = word.toCharArray();
while(j >=k){
if(k==0){
rWord[k]= Character.toUpperCase(wordA[j]);
rWord[j-k]= Character.toLowerCase(wordA[k]);
} else if(j ==k){
rWord[k] = wordA[j];
}
else {
rWord[k] = wordA[j];
rWord[j] = wordA[k];
}
j--;
k++;
}
return rWord;
}
- NoOne October 13, 2016