Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Using Recursion reverse the Line
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
//'main' method must be in a class 'Rextester'. //Compiler version 1.8.0_111 import java.util.*; import java.lang.*; class Rextester { int it=0,wordsIt=0; String words[]=new String[100]; char inputLineArray[]=new char[1000]; String temp=""; int lineLength; public void splitLine() { if(inputLineArray[it]!=' ') { temp=temp+Character.toString(inputLineArray[it]); } else { temp=""; wordsIt++; } it++; words[wordsIt]=temp; if(it<lineLength) splitLine(); else return; } public static void main(String args[]) { Rextester obj=new Rextester(); Scanner input=new Scanner(System.in); System.out.println("Enter the line to be reversed:"); String inputLine=input.nextLine(); obj.inputLineArray=inputLine.toCharArray(); obj.lineLength=inputLine.length(); obj.splitLine(); for(int i=obj.wordsIt;i>=0;i--) System.out.print(obj.words[i]+" "); } }
I am Ramkumar Prabaharan
[
-
]
Show input
Compilation time: 1.75 sec, absolute running time: 0.35 sec, cpu time: 0.35 sec, memory peak: 20 Mb, absolute service time: 2,11 sec
edit mode
|
history
|
discussion
Enter the line to be reversed: Prabaharan Ramkumar am I