Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Months of the year

  1. #1
    Junior Member
    Join Date
    May 2018
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Months of the year

    I've been asked to develop a simple program for my Java class which asks the user to input a number and based on the users response the corresponding month of the year should appear. This has to be achieved through the use of parallel arrays. The program is written in Notepad and compiled via CMD using the javac command. For some reason the code below gives me an error when I try to compile it any input or advice would be appreciated.

    import java.util.Scanner;

    /* Calender.java
    * This program displays the month of the year based on the users input
    * Date created: 5 May 2018 */

    public class Calender
    {
    public static void main(String args[])
    {
    Scanner sc = new Scanner(System.in);
    String[] months = {"January", "February", "March", "April", "May", "June", "July, "August", "September", "October", "November", "December"};
    int[] monthYear = {1, 2, 3, 4, 5 , 6, 7, 8, 9, 10, 11, 12};
    int i;

    System.out.print("Please enter a value to view the corrosponding month");
    i = sc.nextInt();

    for(i = 0; i <= 11; i++)
    {
    System.out.printf("Number %d: %s \n",months[i],monthYear[i]);
    }
    }
    }

  2. #2
    Member John Joe's Avatar
    Join Date
    Jun 2017
    Posts
    277
    My Mood
    Amused
    Thanks
    8
    Thanked 19 Times in 19 Posts

    Default Re: Months of the year

    For some reason the code below gives me an error...
    What is the error?
    Whatever you are, be a good one

  3. #3
    Member
    Join Date
    Dec 2013
    Location
    Honolulu
    Posts
    83
    Thanks
    1
    Thanked 4 Times in 2 Posts

    Default Re: Months of the year

    NetBeans, the latest version would answer all your questions. Download a copy of it, it will be much easier to get the idea. IDE. You know, computers talking to other computers via the Java program or general purpose language. C or C++ was, now it's the internet.

  4. #4
    Junior Member
    Join Date
    Aug 2018
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Months of the year

    The problem is here:

    The mistake in bold:

    String[] months = {"January", "February", "March", "April", "May", "June", "July, "August", "September", "October", "November", "December"};

    the corrected code:

    String[] months = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};

    Regards
    Alin

Similar Threads

  1. Months of the year []
    By #0Prog in forum What's Wrong With My Code?
    Replies: 3
    Last Post: May 7th, 2018, 10:12 PM
  2. Small webapp that determine whether a year is a leap year.
    By frankhvam in forum Object Oriented Programming
    Replies: 0
    Last Post: October 26th, 2013, 03:32 PM
  3. numbered months
    By JavaN00b101 in forum Java Theory & Questions
    Replies: 5
    Last Post: February 8th, 2012, 01:13 PM