+ 1

What is the output of this code? Why ?

public class Year { public enum seasons { Spring, summer, autumn, winter } public static void main (String[] args) { int x = 4 % 3; System.out.println (seasons.values( )[ x]); } }

21st Jul 2018, 3:18 AM
PRINCE MATHEW
PRINCE MATHEW - avatar
2 Answers
+ 7
You have a compile error with va|ues instead of values. Once fixed, x becomes 1 as 4-3 leaves 1. seasons.values()[1] is summer so that gets printed.
21st Jul 2018, 3:44 AM
John Wells
John Wells - avatar
+ 6
Edited your post to add Java tag.
21st Jul 2018, 3:37 AM
John Wells
John Wells - avatar