Java data output “date” and “month”












-2















I'm just looking at getting a program where the user is asked to input day and month in "int" format, say "1" for day and "1" for month will give "1 January".



Have it easy at the start as can just have 1 to 12 linked to "January" etc, but need to have a second string limiting the number of days in each month.



Also, have to have a substring to insert "st" "nd" to the final output, say if day number is "13" output will be "13th".



Have the following so far:



import java.util.Scanner;

public class q1 {

public static void main(String args)
{
Scanner input = new Scanner(System.in);
System.out.print("Enter a month: ");
String first = input.nextLine();
System.out.print("Enter a day: ");
String second = input.nextLine();
input.close();

if (first.charAt(0) == '1') {
first = "January";
} else if (first.charAt(0) == '2') {
first = "February";
else if (first.charAt(0) == '3') {
first = "March";
{
System.out.println("The date entered is the" second + "of " + first);}
}
}


Thanks for any help.










share|improve this question




















  • 2





    Welcome to Stack Overflow! You appear to be asking us to do your homework for you. We will not be doing this, as doing so would not be a benefit to anyone, and in the long term, it will actually be a net harm to you. Please review your class notes and feel free to edit this question to be more specific with where you are having difficulty. Read also: An open letter to students with homework problems

    – Joe C
    Nov 24 '18 at 17:19






  • 2





    Where exactly are you stuck?

    – Nicholas K
    Nov 24 '18 at 17:22











  • Am just stuck where to include a specific part where to limit and ask the user to input day number again, say if "32" is input and is January, would assume "else if >=31" for January would be the logic? Have "Pseudocode" done up just to limit it for this.

    – AFanmhi
    Nov 24 '18 at 17:44
















-2















I'm just looking at getting a program where the user is asked to input day and month in "int" format, say "1" for day and "1" for month will give "1 January".



Have it easy at the start as can just have 1 to 12 linked to "January" etc, but need to have a second string limiting the number of days in each month.



Also, have to have a substring to insert "st" "nd" to the final output, say if day number is "13" output will be "13th".



Have the following so far:



import java.util.Scanner;

public class q1 {

public static void main(String args)
{
Scanner input = new Scanner(System.in);
System.out.print("Enter a month: ");
String first = input.nextLine();
System.out.print("Enter a day: ");
String second = input.nextLine();
input.close();

if (first.charAt(0) == '1') {
first = "January";
} else if (first.charAt(0) == '2') {
first = "February";
else if (first.charAt(0) == '3') {
first = "March";
{
System.out.println("The date entered is the" second + "of " + first);}
}
}


Thanks for any help.










share|improve this question




















  • 2





    Welcome to Stack Overflow! You appear to be asking us to do your homework for you. We will not be doing this, as doing so would not be a benefit to anyone, and in the long term, it will actually be a net harm to you. Please review your class notes and feel free to edit this question to be more specific with where you are having difficulty. Read also: An open letter to students with homework problems

    – Joe C
    Nov 24 '18 at 17:19






  • 2





    Where exactly are you stuck?

    – Nicholas K
    Nov 24 '18 at 17:22











  • Am just stuck where to include a specific part where to limit and ask the user to input day number again, say if "32" is input and is January, would assume "else if >=31" for January would be the logic? Have "Pseudocode" done up just to limit it for this.

    – AFanmhi
    Nov 24 '18 at 17:44














-2












-2








-2








I'm just looking at getting a program where the user is asked to input day and month in "int" format, say "1" for day and "1" for month will give "1 January".



Have it easy at the start as can just have 1 to 12 linked to "January" etc, but need to have a second string limiting the number of days in each month.



Also, have to have a substring to insert "st" "nd" to the final output, say if day number is "13" output will be "13th".



Have the following so far:



import java.util.Scanner;

public class q1 {

public static void main(String args)
{
Scanner input = new Scanner(System.in);
System.out.print("Enter a month: ");
String first = input.nextLine();
System.out.print("Enter a day: ");
String second = input.nextLine();
input.close();

if (first.charAt(0) == '1') {
first = "January";
} else if (first.charAt(0) == '2') {
first = "February";
else if (first.charAt(0) == '3') {
first = "March";
{
System.out.println("The date entered is the" second + "of " + first);}
}
}


Thanks for any help.










share|improve this question
















I'm just looking at getting a program where the user is asked to input day and month in "int" format, say "1" for day and "1" for month will give "1 January".



Have it easy at the start as can just have 1 to 12 linked to "January" etc, but need to have a second string limiting the number of days in each month.



Also, have to have a substring to insert "st" "nd" to the final output, say if day number is "13" output will be "13th".



Have the following so far:



import java.util.Scanner;

public class q1 {

public static void main(String args)
{
Scanner input = new Scanner(System.in);
System.out.print("Enter a month: ");
String first = input.nextLine();
System.out.print("Enter a day: ");
String second = input.nextLine();
input.close();

if (first.charAt(0) == '1') {
first = "January";
} else if (first.charAt(0) == '2') {
first = "February";
else if (first.charAt(0) == '3') {
first = "March";
{
System.out.println("The date entered is the" second + "of " + first);}
}
}


Thanks for any help.







java input output






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 24 '18 at 17:21









Nicholas K

7,39161536




7,39161536










asked Nov 24 '18 at 17:18









AFanmhiAFanmhi

186




186








  • 2





    Welcome to Stack Overflow! You appear to be asking us to do your homework for you. We will not be doing this, as doing so would not be a benefit to anyone, and in the long term, it will actually be a net harm to you. Please review your class notes and feel free to edit this question to be more specific with where you are having difficulty. Read also: An open letter to students with homework problems

    – Joe C
    Nov 24 '18 at 17:19






  • 2





    Where exactly are you stuck?

    – Nicholas K
    Nov 24 '18 at 17:22











  • Am just stuck where to include a specific part where to limit and ask the user to input day number again, say if "32" is input and is January, would assume "else if >=31" for January would be the logic? Have "Pseudocode" done up just to limit it for this.

    – AFanmhi
    Nov 24 '18 at 17:44














  • 2





    Welcome to Stack Overflow! You appear to be asking us to do your homework for you. We will not be doing this, as doing so would not be a benefit to anyone, and in the long term, it will actually be a net harm to you. Please review your class notes and feel free to edit this question to be more specific with where you are having difficulty. Read also: An open letter to students with homework problems

    – Joe C
    Nov 24 '18 at 17:19






  • 2





    Where exactly are you stuck?

    – Nicholas K
    Nov 24 '18 at 17:22











  • Am just stuck where to include a specific part where to limit and ask the user to input day number again, say if "32" is input and is January, would assume "else if >=31" for January would be the logic? Have "Pseudocode" done up just to limit it for this.

    – AFanmhi
    Nov 24 '18 at 17:44








2




2





Welcome to Stack Overflow! You appear to be asking us to do your homework for you. We will not be doing this, as doing so would not be a benefit to anyone, and in the long term, it will actually be a net harm to you. Please review your class notes and feel free to edit this question to be more specific with where you are having difficulty. Read also: An open letter to students with homework problems

– Joe C
Nov 24 '18 at 17:19





Welcome to Stack Overflow! You appear to be asking us to do your homework for you. We will not be doing this, as doing so would not be a benefit to anyone, and in the long term, it will actually be a net harm to you. Please review your class notes and feel free to edit this question to be more specific with where you are having difficulty. Read also: An open letter to students with homework problems

– Joe C
Nov 24 '18 at 17:19




2




2





Where exactly are you stuck?

– Nicholas K
Nov 24 '18 at 17:22





Where exactly are you stuck?

– Nicholas K
Nov 24 '18 at 17:22













Am just stuck where to include a specific part where to limit and ask the user to input day number again, say if "32" is input and is January, would assume "else if >=31" for January would be the logic? Have "Pseudocode" done up just to limit it for this.

– AFanmhi
Nov 24 '18 at 17:44





Am just stuck where to include a specific part where to limit and ask the user to input day number again, say if "32" is input and is January, would assume "else if >=31" for January would be the logic? Have "Pseudocode" done up just to limit it for this.

– AFanmhi
Nov 24 '18 at 17:44












1 Answer
1






active

oldest

votes


















0














For the substring which you need to append to your day, you could look at a map kind of data structure.



Map<Integer, String> daySubstringMap = new TreeMap<>();

{1: "st"}
{2: "nd"}


Or



Map<Set<Integer>, String> daysSubstringMap  = new HashMap<>()

{[1]: "st"}
{[2]: "nd"}
{[4,5,6,7]:"th"}





share|improve this answer
























  • Thanks for this, and this can be referred to in the final output by concatenation?

    – AFanmhi
    Nov 24 '18 at 18:03











  • You can use it as a static map & refer it when you are generating the string

    – unnik
    Nov 24 '18 at 18:06













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53460596%2fjava-data-output-date-and-month%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














For the substring which you need to append to your day, you could look at a map kind of data structure.



Map<Integer, String> daySubstringMap = new TreeMap<>();

{1: "st"}
{2: "nd"}


Or



Map<Set<Integer>, String> daysSubstringMap  = new HashMap<>()

{[1]: "st"}
{[2]: "nd"}
{[4,5,6,7]:"th"}





share|improve this answer
























  • Thanks for this, and this can be referred to in the final output by concatenation?

    – AFanmhi
    Nov 24 '18 at 18:03











  • You can use it as a static map & refer it when you are generating the string

    – unnik
    Nov 24 '18 at 18:06


















0














For the substring which you need to append to your day, you could look at a map kind of data structure.



Map<Integer, String> daySubstringMap = new TreeMap<>();

{1: "st"}
{2: "nd"}


Or



Map<Set<Integer>, String> daysSubstringMap  = new HashMap<>()

{[1]: "st"}
{[2]: "nd"}
{[4,5,6,7]:"th"}





share|improve this answer
























  • Thanks for this, and this can be referred to in the final output by concatenation?

    – AFanmhi
    Nov 24 '18 at 18:03











  • You can use it as a static map & refer it when you are generating the string

    – unnik
    Nov 24 '18 at 18:06
















0












0








0







For the substring which you need to append to your day, you could look at a map kind of data structure.



Map<Integer, String> daySubstringMap = new TreeMap<>();

{1: "st"}
{2: "nd"}


Or



Map<Set<Integer>, String> daysSubstringMap  = new HashMap<>()

{[1]: "st"}
{[2]: "nd"}
{[4,5,6,7]:"th"}





share|improve this answer













For the substring which you need to append to your day, you could look at a map kind of data structure.



Map<Integer, String> daySubstringMap = new TreeMap<>();

{1: "st"}
{2: "nd"}


Or



Map<Set<Integer>, String> daysSubstringMap  = new HashMap<>()

{[1]: "st"}
{[2]: "nd"}
{[4,5,6,7]:"th"}






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 24 '18 at 17:38









unnikunnik

45711124




45711124













  • Thanks for this, and this can be referred to in the final output by concatenation?

    – AFanmhi
    Nov 24 '18 at 18:03











  • You can use it as a static map & refer it when you are generating the string

    – unnik
    Nov 24 '18 at 18:06





















  • Thanks for this, and this can be referred to in the final output by concatenation?

    – AFanmhi
    Nov 24 '18 at 18:03











  • You can use it as a static map & refer it when you are generating the string

    – unnik
    Nov 24 '18 at 18:06



















Thanks for this, and this can be referred to in the final output by concatenation?

– AFanmhi
Nov 24 '18 at 18:03





Thanks for this, and this can be referred to in the final output by concatenation?

– AFanmhi
Nov 24 '18 at 18:03













You can use it as a static map & refer it when you are generating the string

– unnik
Nov 24 '18 at 18:06







You can use it as a static map & refer it when you are generating the string

– unnik
Nov 24 '18 at 18:06






















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53460596%2fjava-data-output-date-and-month%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

To store a contact into the json file from server.js file using a class in NodeJS

Redirect URL with Chrome Remote Debugging Android Devices

Dieringhausen