File tree Expand file tree Collapse file tree 19 files changed +385
-1
lines changed Expand file tree Collapse file tree 19 files changed +385
-1
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * @author MadhavBahlMD
3
+ * @date 25/01/2019
4
+ */
5
+
6
+ import java .util .Scanner ;
7
+
8
+ public class CircleArea {
9
+ public static double area (double radius ) {
10
+ return Math .PI *radius *radius ;
11
+ }
12
+
13
+ public static void main (String [] args ) {
14
+ Scanner input = new Scanner (System .in );
15
+ System .out .println ("/* ===== Area of Circle ===== */" );
16
+ System .out .print ("\n Enter the radius: " );
17
+ double radius = input .nextDouble ();
18
+ System .out .println ("Area of circle is: " + area (radius ));
19
+ }
20
+ }
Original file line number Diff line number Diff line change
1
+ # Circle Area
2
+
3
+ WAP to read the radius and print the area of a circle
4
+
5
+ ## Solution
6
+
7
+ ### [ Java Implementation] ( ./CircleArea.java )
8
+
9
+ ``` java
10
+ /**
11
+ * @author MadhavBahlMD
12
+ * @date 25/01/2019
13
+ */
14
+
15
+ import java.util.Scanner ;
16
+
17
+ public class CircleArea {
18
+ public static double area (double radius ) {
19
+ return Math . PI* radius* radius;
20
+ }
21
+
22
+ public static void main (String [] args ) {
23
+ Scanner input = new Scanner (System . in);
24
+ System . out. println(" /* ===== Area of Circle ===== */" );
25
+ System . out. print(" \n Enter the radius: " );
26
+ double radius = input. nextDouble();
27
+ System . out. println(" Area of circle is: " + area(radius));
28
+ }
29
+ }
30
+ ```
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @author MadhavBahlMD
3
+ * @date 26/01/2019
4
+ */
5
+
6
+ import java .util .Scanner ;
7
+
8
+ public class LeapYear {
9
+ public static Boolean checkLeapYear (int year ) {
10
+ if ((year %4 == 0 && year %100 != 0 ) || (year %400 == 0 )) return true ;
11
+ else return false ;
12
+ }
13
+
14
+ public static void main (String [] args ) {
15
+ Scanner input = new Scanner (System .in );
16
+ System .out .println ("/* ===== Check Leap Year ===== */" );
17
+ System .out .print ("\n Enter the year: " );
18
+ int year = input .nextInt ();
19
+
20
+ if (checkLeapYear (year )) System .out .println ("Yes, " + year + " is a Leap Year!" );
21
+ else System .out .println ("No, " + year + " is not a leap year!" );
22
+ }
23
+ }
Original file line number Diff line number Diff line change
1
+ # Leap Year
2
+
3
+ WAP to check whether the given year is a leap year or not
4
+
5
+ ## Solution
6
+
7
+ ### [ Java Implementation] ( ./LeapYear.java )
8
+
9
+ ``` java
10
+ /**
11
+ * @author MadhavBahlMD
12
+ * @date 26/01/2019
13
+ */
14
+
15
+ import java.util.Scanner ;
16
+
17
+ public class LeapYear {
18
+ public static Boolean checkLeapYear (int year ) {
19
+ if ((year% 4 == 0 && year% 100 != 0 ) || (year% 400 == 0 )) return true ;
20
+ else return false ;
21
+ }
22
+
23
+ public static void main (String [] args ) {
24
+ Scanner input = new Scanner (System . in);
25
+ System . out. println(" /* ===== Check Leap Year ===== */" );
26
+ System . out. print(" \n Enter the year: " );
27
+ int year = input. nextInt();
28
+
29
+ if (checkLeapYear(year)) System . out. println(" Yes, " + year + " is a Leap Year!" );
30
+ else System . out. println(" No, " + year + " is not a leap year!" );
31
+ }
32
+ }
33
+ ```
Original file line number Diff line number Diff line change
1
+ /**
2
+ * Natural Sum using recursion
3
+ * @author MadhavBahlMD
4
+ * @date 26/01/2019
5
+ */
6
+
7
+ import java .util .Scanner ;
8
+
9
+ public class NaturalSum {
10
+ public static int naturalSum (int n ) {
11
+ if (n <= 0 ) return 0 ;
12
+ else return n +naturalSum (n -1 );
13
+ }
14
+
15
+ public static void main (String [] args ) {
16
+ Scanner input = new Scanner (System .in );
17
+ System .out .println ("/* ===== Sum N Natural Numbers ===== */" );
18
+ System .out .print ("\n Enter a natural number n: " );
19
+ int n = input .nextInt ();
20
+ System .out .println ("The sum of first " + n + " natural numbers = " + naturalSum (n ));
21
+ }
22
+ }
Original file line number Diff line number Diff line change
1
+ # Natural Sum
2
+
3
+ WAP to sum first ` n ` natural numbers
4
+
5
+ ## Solution
6
+
7
+ ### [ Java Solution] ( ./NaturalSum.java )
8
+
9
+ ``` java
10
+ /**
11
+ * Natural Sum using recursion
12
+ * @author MadhavBahlMD
13
+ * @date 26/01/2019
14
+ */
15
+
16
+ import java.util.Scanner ;
17
+
18
+ public class NaturalSum {
19
+ public static int naturalSum (int n ) {
20
+ if (n <= 0 ) return 0 ;
21
+ else return n+ naturalSum(n- 1 );
22
+ }
23
+
24
+ public static void main (String [] args ) {
25
+ Scanner input = new Scanner (System . in);
26
+ System . out. println(" /* ===== Sum N Natural Numbers ===== */" );
27
+ System . out. print(" \n Enter a natural number n: " );
28
+ int n = input. nextInt();
29
+ System . out. println(" The sum of first " + n + " natural numbers = " + naturalSum(n));
30
+ }
31
+ }
32
+ ```
Original file line number Diff line number Diff line change
1
+ import java .util .Scanner ;
2
+
3
+ /**
4
+ * @author MadhavBahlMD
5
+ * @date 25/01/2019
6
+ */
7
+
8
+ public class OddEven {
9
+ public static void main (String [] args ) {
10
+ Scanner input = new Scanner (System .in );
11
+ System .out .println ("/* ===== Check Odd/Even ===== */" );
12
+ System .out .print ("\n Enter the number: " );
13
+ int num = input .nextInt ();
14
+
15
+ if (num %2 == 0 ) System .out .println (num + " is Even!" );
16
+ else System .out .println (num + " is Odd!" );
17
+ }
18
+ }
Original file line number Diff line number Diff line change
1
+ # Odd Even
2
+
3
+ Give a number, write a program to check whether it is odd or even
4
+
5
+ ## Solution
6
+
7
+ ### [ Java Implementation] ( ./OddEven.java )
8
+
9
+ ``` java
10
+ import java.util.Scanner ;
11
+
12
+ /**
13
+ * @author MadhavBahlMD
14
+ * @date 25/01/2019
15
+ */
16
+
17
+ public class OddEven {
18
+ public static void main (String [] args ) {
19
+ Scanner input = new Scanner (System . in);
20
+ System . out. println(" /* ===== Check Odd/Even ===== */" );
21
+ System . out. print(" \n Enter the number: " );
22
+ int num = input. nextInt();
23
+
24
+ if (num% 2 == 0 ) System . out. println(num + " is Even!" );
25
+ else System . out. println(num + " is Odd!" );
26
+ }
27
+ }
28
+
29
+ ```
Original file line number Diff line number Diff line change
1
+ # Bonus Problems -- Miscellaneous
2
+
3
+ Some Miscellaneous Problems to practise! Keep Coding :)
4
+
5
+ ## Questions
6
+
7
+ 1 . [ Odd/Even] ( ./OddEve/ )
8
+ 2 . [ Area of Circle] ( ./CircleArea )
9
+ 3 . [ Check Leap Year] ( ./LeapYear )
10
+ 4 . [ Sum Natural Numbers] ( ./NaturalSum/ )
11
+ 5 . [ Sum of Squares of N natural numbers] ( ./SumSquares/ )
Original file line number Diff line number Diff line change
1
+ # Sum Squares
2
+
3
+ WAP to print the sum of the series 12+22+32 up to n terms
4
+
5
+ ## Solution
6
+
7
+ ### [ Java Implementation] ( ./SumSquares.java )
8
+
9
+ ``` java
10
+ import java.util.Scanner ;
11
+
12
+ public class SumSquares {
13
+ public static int sum (int n ) {
14
+ if (n <= 0 ) return 0 ;
15
+ else return (n* n) + sum(n- 1 );
16
+ }
17
+
18
+ public static void main (String [] args ) {
19
+ Scanner input = new Scanner (System . in);
20
+ System . out. println(" /* ===== Sum of squares of n natural numbers ===== */" );
21
+ System . out. print(" \n Enter the number n: " );
22
+ int n = input. nextInt();
23
+ System . out. println(" sum of squares of " + n + " natural numbers = " + sum(n));
24
+ }
25
+ }
26
+ ```
You can’t perform that action at this time.
0 commit comments