0

Can enhanced for loop be used for initialisation? It didn't work for me......all elements got initialised with zero. ...

for(int i:arr) t=myvar.nextInt();

28th Nov 2017, 9:32 AM
Gokul Krishna
Gokul Krishna - avatar
5 Answers
+ 1
thanks a lot!!!!
28th Nov 2017, 3:16 PM
Gokul Krishna
Gokul Krishna - avatar
0
//this was the code package arrays; import java.util.Scanner; /** * * @author gokul */ public class array { public static void main(String[] args){ int n; System.out.println("enter n"); Scanner myvar=new Scanner(System.in); n=myvar.nextInt(); int arr[]= new int[n]; for(int i:arr) i=myvar.nextInt(); System.out.println("\n your array is ..."); for(int t:arr) System.out.println("\n "+t); } }
28th Nov 2017, 12:04 PM
Gokul Krishna
Gokul Krishna - avatar