Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added question and solution of "Number of days in a month" #86

Merged
merged 4 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Beginner Level πŸ“/Number of days in a month/question.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Number of days in a month
<div>Q: Input the number of the month, calculate the number of days present in that particular month.<br><strong>Note: </strong>Consider non-leap year.<p>&nbsp;</p>
<strong>Example 1: </strong><br><pre><strong>Input: </strong>10<br><strong>Output: </strong>31<br><strong>Explaination: </strong>October has 31 days</pre>
<strong>Example 2: </strong><br><pre><strong>Input: </strong>2<br><strong>Output: </strong>28<br><strong>Explaination: </strong>February has 28 days</pre>
<strong>Example 3: </strong><br><pre><strong>Input: </strong>11<br><strong>Output: </strong>30<br><strong>Explaination: </strong>November has 30 days</pre><br>
<strong>Contraints: </strong><br>1 <= month <= 12
</div>
31 changes: 31 additions & 0 deletions Beginner Level πŸ“/Number of days in a month/solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

//number of days in a month
import java.util.*;

public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("Enter a month number of your choice (between 1 to 12): ");
int m = sc.nextInt(); //here "m" refers to month
int n; // here "n" refers to number of days
if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12){
n = 31; //jan, mar, may, july, aug, oct, dec
}
else if(m == 2) {
n = 28; //feb
}
else
n = 30; //rest months i.e apr, june, sep, nov

System.out.println ("Number of days in this particular month: ");
System.out.println(n);
}
}

/*
// Output:
Enter a month number of your choice (between 1 to 12):
3
Number of days in this particular month:
31
*/
4 changes: 4 additions & 0 deletions Beginner Level πŸ“/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,9 @@
{
"name": "Ghanshyam Saini",
"githubUsername": "Ghanshyam07"
},
{
"name": "Neyna Nayak",
"githubUsername":"neyhere07"
}
]
Loading