0
Why is my program accepting and printing 1 less inputs than the entered length?
import java.util.*; public class Program { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); String ar[]=new String[n]; int a=1; for(int i=0;i<n;i++){ ar[i]=sc.nextLine(); } for(int i=0;i<n;i++){ System.out.println(ar[i]); } } }
1 Respuesta
+ 4
Try it with n +=1 and "i <= n;".