Logic and Design

Logic and Design

Please help me with this Write a program that prompts and accepts a number between 1 and 12. After getting the input, display the number with the appropriate month. (example: This is the 1st month¦January, This is the 2nd month¦February, This is the 12th month¦December).

Thanks

View Answers

January 23, 2012 at 5:47 PM

import java.text.*;
import java.util.*;

class PrintMonth 
{
    public static String getMonthForInt(int m) {
    String month = "invalid";
    DateFormatSymbols dfs = new DateFormatSymbols();
    String[] months = dfs.getMonths();
    if (m >= 0 && m <= 11 ) {
        month = months[m];
    }
    return month;
}
    public static void main(String[] args) 
    {
        Scanner input=new Scanner(System.in);
        System.out.print("Enter number between 1 and 12: ");
        int num=input.nextInt()-1;
        System.out.println("Month is: "+getMonthForInt(num));
    }
}

January 23, 2012 at 6:22 PM

	//please reply if my post really helps
	import java.io.*;
	class Month
	{
	public static void main()throws IOException
	{
	BufferedReader in= new BufferedReader(new InputStreamReader(System.in));
	System.out.println("Enter number between 1 and 12: ");
	int num=Integer.parseInt(in.readLine());
	String mn[]={January,February,March,April,May,June,July,August,September,Octobr,November,December};
	if(num==1)
	System.out.println(num+"st month "+mn[num-1];
	else if(num==2)
	System.out.println(num+"nd month "+mn[num-1];
	else if(i==3)
	System.out.println(num+"rd month "+mn[num-1];
	else
	System.out.println(num+"th month "+mn[num-1];
	}
	}



January 23, 2012 at 6:24 PM

//copy the previous code in notepad and run in bluej

Ads









Related Tutorials/Questions & Answers:
Logic and Design
Logic and Design  Please help me with this Write a program that prompts and accepts a number between 1 and 12. After getting the input, display the number with the appropriate month. (example: This is the 1st month¦January
LOGIC
LOGIC  hey guys..i have my exams coming in somedays and it would be really helpful if someone explained how to develop the logic of any program
Advertisements
LOGIC
LOGIC  hey guys..i have my exams coming in somedays and it would be really helpful if someone explained how to develop the logic of any program
Logic and desgin
Logic and desgin  How would this be put in visual logic symbol
Logic and Degin
Logic and Degin  Need help in writing a pseudocode for this can so please help me with this just need to get started. In this lab, you are going... will modify the existing code to create a modularized design. Load the array via
Logic Building
Logic Building  I wanted to devlop my logic ? How can i do so ? Can i start with java or i need to do c++ before
Logic Iterate.
Logic Iterate.  I have one doubt about logic:iterate. I use text feild inside of logic:iterate , there is possible will generate N no of rows (text feild) inside of iterate. my doubt is how to get the Paritcular rows text
Logic Iterate.
Logic Iterate.  logic iterate Struts I have one doubt about logic:iterate. I use text field inside of logic:iterate , there is possible... the Particular rows text value. for example: print("<logic:iterate id="xid
What is programming logic ?
What is programming logic ?  What is programming logic
logic-iterate
logic-iterate  in my code i am using for-each loop for displaying data i want use tag to display data how to use plase help me <%@ page import="java.sql.*" %> <%String[] id = (String[])session.getAttribute("ids
Design pattern
Design pattern  explain factory pattern
ModuleNotFoundError: No module named 'logic'
ModuleNotFoundError: No module named 'logic'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'logic' How to remove the ModuleNotFoundError: No module named 'logic'
what is the logic of this pattern?
what is the logic of this pattern?   1 121 12321 1234321
Version of com.thesett>logic dependency
List of Version of com.thesett>logic dependency
struts logic tags
struts logic tags  what is the use of struts logic tag   The purpose of Struts logic tags is to alter output depending on the given...://www.roseindia.net/struts/struts-logictags/logic-tags-introduction.shtml http
Design Patterns
Design Patterns  Explain the Factory Pattern, VO Pattern, DAO Pattern, and Singleton Pattern
DESIGN PATTERNS
DESIGN PATTERNS  How many instances will be created for single ton pattern in Cluster Environment
About Web-Logic
the Web-Logic with Tomcat 5.0 version in Console. Somebody has suggested to see the webpage (they had given the link).But when i installed the Web-Logic i... folder in the Web-Logic
Struts logic iterate
Struts logic iterate  This is my jsp page in which i used 3 logic...; <%@taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>...; <body> <h1> Search </h1> <logic:iterate name
logic for pattern program
logic for pattern program  what's the logic for create pattern program how can i create any pattern program with in minute. like this 123454321... create this program in java without help whats the logic how can i understand
Java - Design concepts & design patterns
Java  Sir , please let me know the exact usage of DAO design pattern  Hi Friend, Please visit the following link: http://www.roseindia.net/javatutorials/J2EE_singleton_pattern.shtml Thanks
logic for c language
logic for c language  01 02 03 04 05 06 20 21 22 23 24 07 19 32 33 34 25 08 18 31 36 35 26 09 17 30 29 28 27 10 16 15 14 13 12 11
Javascript - Design concepts & design patterns
Javascript  Dear Sir, how to attach file while sending some files in a mail service??i have a button called attach files.After clickin that button what is the function to be called.Please give me some design code
Tell us the logic of diceroller
Tell us the logic of diceroller  import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class DiceRollerServlet extends... is " +dice2); } } dice1 =3 dice2 =2 How is the logic executed????   
Database Design
Database Design To design the database you first need to install the MySql database. The After create the database as create database if not exists `onlinexamination`; Then create the table new_ques which contains the queshon
Please explain the logic....
Please explain the logic....  class A1 { } class B extends A1 { } public class ComingThru { static String s = "-"; public static void main(String[] args) { A1[] aa = new A1[2]; B[] ba = new B[2
ModuleNotFoundError: No module named 'django-logic'
ModuleNotFoundError: No module named 'django-logic'  Hi, My Python... 'django-logic' How to remove the ModuleNotFoundError: No module named 'django-logic' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'fuzzy_logic'
ModuleNotFoundError: No module named 'fuzzy_logic'  Hi, My Python... 'fuzzy_logic' How to remove the ModuleNotFoundError: No module named 'fuzzy_logic' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'geohash_logic'
ModuleNotFoundError: No module named 'geohash_logic'  Hi, My... 'geohash_logic' How to remove the ModuleNotFoundError: No module named 'geohash_logic' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'json-logic'
ModuleNotFoundError: No module named 'json-logic'  Hi, My Python... 'json-logic' How to remove the ModuleNotFoundError: No module named 'json-logic' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'logic-circuit-dave22153'
ModuleNotFoundError: No module named 'logic-circuit-dave22153'  Hi...: No module named 'logic-circuit-dave22153' How to remove the ModuleNotFoundError: No module named 'logic-circuit-dave22153' error? Thanks   

Ads