Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here is my code without split() for you. </p> <p>Input: India is my country</p> <p>Output:</p> <p>country my is India </p> <p>aidnI si ym yrtnuoc</p> <p>You can choose the output you need.</p> <pre><code>public class Reverse { public static class Stack { private Node[] slot = new Node[1000]; private int pos = 0; private class Node{ private char[] n = new char[30]; private int pos = 0; public void push(char c) { n[pos++] = c; } public String toString() { return new String(n).trim() + " "; // TODO Fix } } public void push(char c) { if(slot[pos] == null) slot[pos] = new Node(); if(c != ' ') { slot[pos].push(c); } else { slot[pos++].push(c); } } public String toString() { StringBuilder sb = new StringBuilder(); for(int i = pos; i &gt;=0; i --) sb.append(slot[i]); return sb.toString(); } private String reverseWord(String word) { StringBuilder sb = new StringBuilder(); int len = word.length(); for(int i = len - 1; i &gt;= 0; i--) sb.append(word.charAt(i)); return sb.toString(); } public String foryou() { StringBuilder sb = new StringBuilder(); for(int i = 0; i &lt; pos + 1; i ++) sb.append(this.reverseWord(slot[i].toString())); return sb.toString(); } } /** * @param args */ public static void main(String[] args) { Stack stack = new Stack(); String sentence = "India is my country"; System.out.println(sentence); for(int i = 0; i &lt; sentence.length(); i ++) { stack.push(sentence.charAt(i)); } System.out.println(stack); System.out.println(stack.foryou()); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload