Results 1 to 5 of 5
Thread: Initailization
- 03-24-2012, 10:17 AM #1
Member
- Join Date
- Mar 2012
- Posts
- 10
- Rep Power
- 0
- 03-24-2012, 10:36 AM #2
Senior Member
- Join Date
- Oct 2011
- Posts
- 106
- Rep Power
- 0
Re: Initailization
Did you try this code?What happened? What do you mean by "be used in a enhanced for loop"?
- 03-24-2012, 10:43 AM #3
Member
- Join Date
- Mar 2012
- Posts
- 10
- Rep Power
- 0
- 03-24-2012, 10:57 AM #4
Senior Member
- Join Date
- Oct 2011
- Posts
- 106
- Rep Power
- 0
Re: Initailization
Here's more than enough to get you going in the right direction. The one thing you have to be cognizant of in taking this approach, is in what ways shallow or deep copying will affect the processing of your application.
start here:
Java Code:static Scanner console = new Scanner(System.in); public static void main(String[] args) { int y; System.out.println("Enter:"); y = console.nextInt(); int[] day = new int[0]; if(y % 4 == 0) { int[] days = {1,2,3}; day = days; } else { int[] days ={5,6, 7, 8, 9,0}; day = days; } for(int n : day) { System.out.print(n + " "); } }
- 03-24-2012, 11:03 AM #5
Senior Member
- Join Date
- Jun 2007
- Location
- Bali, Indonesia
- Posts
- 696
- Rep Power
- 6
Re: Initailization
It means that your day array is not accessible within the for-each loop block. This is happen because your day variable is declared inside the if statement block. To let the for block have access to it, declare your array before the if block. You can the initialize it inside your if block and iterate it using the for-each statement.
Website: Learn Java by Examples


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks