-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #86 from neyhere07/main
Added question and solution of "Number of days in a month"
- Loading branch information
Showing
3 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> </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
31
Beginner Level π/Number of days in a month/solution.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters