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 1 of 1

Thread: PRINTING THE NAME OF THE MONTH AFTER THE INPUTTED NUMBER

  1. #1
    Member
    Join Date
    Mar 2014
    Posts
    92
    My Mood
    Inspired
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default PRINTING THE NAME OF THE MONTH AFTER THE INPUTTED NUMBER

    Hi,
    I completed my code which allows the user to input a number and the corresponding month is outputted.
    However, when I test my program, no output is produced.

    Eg. I entered 1 but nothing was printed.

    Please assist.

     
    import java.util.Scanner;
     
    public class PrintMonth {
    	public static void main (String[]args){
    		Scanner in = new Scanner(System.in);
    		System.out.printf("Enter a month from 1 to 12\n");
    		int n = in.nextInt();
    		System.out.printf("%s \n",nameOfMonth(in.nextInt(n)));
    	}//end main
     
     
    	public static String nameOfMonth(int n) {
    		String[] month = {"","Jamuary", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
    		if (n <1 || n >12)
    		{
    			return "Invalid day";
    		}
    		return month[n];
        }//end method
    }//end class


    --- Update ---

    Well after my post, I saw my error.
    My program is working well now .
    Last edited by Java girl; April 13th, 2014 at 04:03 PM.


Similar Threads

  1. Generating a random number from a range of inputted numbers
    By R0bert199O in forum What's Wrong With My Code?
    Replies: 3
    Last Post: September 25th, 2013, 01:48 PM
  2. [SOLVED] Why is system.println printing a reference number
    By cowsquad in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 19th, 2013, 01:33 PM
  3. How to store a number that was inputted by the user? please help
    By shep in forum Java Theory & Questions
    Replies: 3
    Last Post: December 1st, 2012, 10:52 AM
  4. Java program inputting month name and outputting month number and number of days
    By Brovahkiin501 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: September 19th, 2012, 09:30 AM
  5. Printing Sum of Primes of a number
    By CodeNewb in forum What's Wrong With My Code?
    Replies: 9
    Last Post: July 12th, 2010, 01:25 PM