Easy Solution ----- Beginner Friendly--- Rverse of Word in String... package Programs; import java.util.ArrayList; import java.util.Iterator; public class Reverseword { public static void main(String[] args) {
String str="I love java programming"; int end=str.length();
#javainterviewquestions
Nice mock.. Thank rakesh sir👍
Ask some tough questions sir plz
I think the example for constructor overloading is not correct because she provided return type "void" for constructor.
Easy Solution ----- Beginner Friendly--- Rverse of Word in String...
package Programs;
import java.util.ArrayList;
import java.util.Iterator;
public class Reverseword {
public static void main(String[] args) {
String str="I love java programming";
int end=str.length();
ArrayList ar=new ArrayList();
for(int i=str.length()-1;i>=0;i--)
{
if(str.charAt(i)==' ')
{
ar.add(str.substring(i+1,end));
end=i;
}
else if(i==0)
{
ar.add(str.substring(i,end));
}
}
Iterator it=ar.iterator();
while(it.hasNext())
{
System.out.print(it.next()+" ");
}
}
}