File tree Expand file tree Collapse file tree 4 files changed +62
-0
lines changed
Java Programming Principles 2/Homework/4. Unit Four/3. Ch 15 Program Challenges
1. Recursive Multiplication/src Expand file tree Collapse file tree 4 files changed +62
-0
lines changed Original file line number Diff line number Diff line change 1+ /*
2+ * This program was written by Kyle Martin on 7/31/2021 for Java Programming Principles 2 during Summer Session 2
3+ * at Southwestern College, Kansas.
4+ *
5+ * IMPORTANT: Normally I would not place a bunch of comments in my code describing what my code is doing as I like to
6+ * have code that is written in a manner to be understandable while reading it. Though, do to the grading rubric I will
7+ * explain my code.
8+ *
9+ * This program was created to perform multiplication of two given integers using recursion
10+ * See Chapter 15 Programming Challenges - Challenge One.
11+ */
12+ import java .util .Scanner ;
13+
14+ public class RecursiveMultiplication {
15+ public static void main (String [] args ) {
16+ Scanner scanner = new Scanner (System .in );
17+ int x , y ;
18+ System .out .println ("Enter the first number:" );
19+ x = scanner .nextInt ();
20+ System .out .println ("Enter the second number:" );
21+ y = scanner .nextInt ();
22+
23+ int result = multiplication (x , y );
24+
25+ System .out .println (x + " times " + y + " is " + result );
26+ scanner .close ();
27+ }
28+
29+ private static int multiplication (int x , int y ) {
30+ if (y != 0 ) {
31+ return (x + multiplication (x , y -1 ));
32+ } else {
33+ return 0 ;
34+ }
35+ }
36+ }
Original file line number Diff line number Diff line change 1+ /*
2+ * This program was written by Kyle Martin on 7/31/2021 for Java Programming Principles 2 during Summer Session 2
3+ * at Southwestern College, Kansas.
4+ *
5+ * IMPORTANT: Normally I would not place a bunch of comments in my code describing what my code is doing as I like to
6+ * have code that is written in a manner to be understandable while reading it. Though, do to the grading rubric I will
7+ * explain my code.
8+ *
9+ * This program was created to use recursive to print a string in reverse
10+ * See Chapter 15 Programming Challenges - Challenge Three.
11+ */
12+ public class StringReverser {
13+ public static void main (String [] args ) {
14+ String string = "This is a string." ;
15+ System .out .println ("String in normal sequence: " + string );
16+ System .out .println ("String in reverse sequence: " );
17+ reverseString (string ,(string .length ()-1 ));
18+ }
19+
20+ private static void reverseString (String string , int i ) {
21+ if (i >= 0 ) {
22+ System .out .print (string .charAt (i ));
23+ reverseString (string , i - 1 );
24+ }
25+ }
26+ }
You can’t perform that action at this time.
0 commit comments