Skip to content

Commit

Permalink
Merge pull request #86 from neyhere07/main
Browse files Browse the repository at this point in the history
Added question and solution of "Number of days in a month"
  • Loading branch information
Kushal997-das authored Oct 23, 2024
2 parents 4dfafaf + 661ce35 commit 879ddd8
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
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"
}
]

0 comments on commit 879ddd8

Please sign in to comment.