Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Using Recursion reverse the Line
//'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]+" "); } }
run
|
edit
|
history
|
help
0
Leetcode 297. Serialize and Deserialize Binary Tree
// Java Coding Challenge - 08: Reversing a Number using String
Current date and time in java
Fireball Plugin
2
클래스의 정의와 인스턴스 생성
PE #3
Alphabets
Sum of power of digits-1
Link document