Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use the following program to do the above questions: // creating more recursive methods for Lab 7 import java.util.Scanner; public class Lab7Recursions { public static

image text in transcribed

image text in transcribed

Use the following program to do the above questions:

// creating more recursive methods for Lab 7

import java.util.Scanner;

public class Lab7Recursions {

public static void main(String args[]) {

int num1, num2;

String wrd1, wrd2;

Scanner scan = new Scanner(System.in);

System.out.print("Enter an integer for testing summationSquare method: ");

num1 = scan.nextInt();

System.out.println("summationSquare(" + num1+") is equal to "+ summationSquare(num1));

System.out.print("Enter an integer for testing the toBinary method: ");

num1 = scan.nextInt();

System.out.print(num1+"(10) is equal to ");

toBinary(num1);

System.out.println("(2)");

System.out.print("Enter an integer for testing ReverseNum method: ");

num1 = scan.nextInt();

System.out.println("reverseNum("+num1+") is equal to "+ reverseNum(num1));

System.out.print("Enter two words for testing equal method:");

wrd1 = scan.next();

wrd2 = scan.next();

System.out.println("equal(\"" +wrd1 +"\",\""+wrd2+"\") is " + equal(wrd1,wrd2));

} //method main

//other class methods

public static long summationSquare (int n){

// summation from 1^2 to n^2

}//method summationSquare

public static void toBinary (int n){

//print n as a binary stream

}// method toBinary

private static long reverse(long n, long tempresult) {

//compute and return the reverse form of n using tempresult

}

public static long reverseNum (long n){

return reverse (n, 0);

} // method reverseNum

private static boolean isEqual (String word1, String word2, int index){

//compare character by character between word1 and word2

}

public static boolean equal (String word1, String word2){

return isEqual (word1, word2, 0);

}

}//class Recursion

3. Write a few recursive methods to compute some specific values or perform some specific tasks as specified below: i. I 15%) Compute the sum from 12 to n^2 , where n is an input integer. For examples: n-10, summationSquare(10) is equal to 385 n-20, summationSquare(20) is equal to 2870 115%) Print out the binary stream of the value n, where n is an input integer For examples: n-123, 123(10) is equal to 1111011(2) n -234, -234(10 is equal to -1101010(2)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Readings In Database Systems

Authors: Michael Stonebraker

2nd Edition

0934613656, 9780934613651

More Books

Students also viewed these Databases questions

Question

What is the role of the Joint Commission in health care?

Answered: 1 week ago