CodeGym
Promotion
CodeGym University
Learning
Course
Tasks
Surveys & Quizzes
Games
Help
Schedule
Community
Users
Forum
Chat
Articles
Success stories
Activity
Reviews
Subscriptions
Light theme
Question
  • Reviews
  • About us
Start
Start learning
Start learning now
  • All questions
null
Level 26
Orlando
  • 03.03.2020
  • 757views
  • 1comment

I thought enum was also a java collection. This make it more simple than using ArrayList tho.

Question about the task Month number
Java Syntax,  Level 8,  Lesson 11
Under discussion
The program reads the name of the month from the keyboard and then displays its number on the screen in a phrase like: "May is month 5".
Use collections.

Requirements:
  • The program should read one value from the keyboard.
  • The program should display text on the screen.
  • The program must use collections.
  • The program should read from the keyboard the name of the month and display its number on the screen according to the specified template.
package com.codegym.task.task08.task0828; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.HashSet; import java.util.HashMap; import java.util.List; import java.util.Set; /* Month number */ public class Solution { enum Month{ January, February, March, April, May, June, July, August, September, October, November, December } public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String monthName = reader.readLine(); Month month = Month.valueOf(monthName); System.out.println(monthName + " is month "+(month.ordinal() + 1)); } }
0
Comments (1)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Anonymous #10410173 Full Stack Developer
4 March 2020, 12:14
you should use collection
0
Learn
  • Registration
  • Java Course
  • Help with Tasks
  • Pricing
  • Game Projects
  • Java Syntax
Community
  • Users
  • Articles
  • Forum
  • Chat
  • Success Stories
  • Activity
  • Affiliate Program
Company
  • About us
  • Contacts
  • Reviews
  • Press Room
  • CodeGym for EDU
  • FAQ
  • Support
CodeGym CodeGym is an online course for learning Java programming from scratch. This course is a perfect way to master Java for beginners. It contains 1200+ tasks with instant verification and an essential scope of Java fundamentals theory. To help you succeed in education, we’ve implemented a set of motivational features: quizzes, coding projects, content about efficient learning and Java developer’s career.
Follow us
Interface language
Programmers Are Made, Not Born © 2023 CodeGym
MastercardVisa
Programmers Are Made, Not Born © 2023 CodeGym
This website uses cookies to provide you with personalized service. By using this website, you agree to our use of cookies. If you require more details, please read our Terms and Policy.