Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

public class Main {

    public static void main(String[] args) {
        String s = new String(revStr("hello brave new world"));
        String st = new String(revWords("hello brave new world"));
        System.out.println(s);
        System.out.println(st);
    }

    public static String revStr(String s) {
        StringBuilder sb = new StringBuilder();
        for (int i = s.length() - 1; i >= 0; i--) {
            sb.append(s.charAt(i));
        }
        return sb.toString();
    }

    public static String revWords(String str) {
        StringBuilder sb = new StringBuilder();
        String revd = revStr(str);
        for (String s : revd.split(" ")) {
            sb.append(revStr(s));
            sb.append(" ");
        }
        return sb.toString();
    }

}