0

why this loop is running only two times while taking input

import java.util.*; class Reverse { public static void main(String[] arr) { Scanner sc=new Scanner(System.in); int n=3; String[] lin=new String[n]; for(int i=0;i<3;i++){ lin[i]=sc.nextLine(); } for(int i=0;i<3;i++){ String[] revl=lin[i].split(" "); for(int j=revl.length-1;j>=0;j--) { System.out.print(revl[j]+" "); } System.out.println(); } } }

10/7/2016 2:27:26 PM

Aamir Alam

3 Answers

New Answer

+2

Both of your for statements are increasing i. Try changing one of the i variables then it should run 9 times

+2

put a different counter variable in for your second for loop

0

thanks