Write a method that takes two strings as parameters and


1. Consider the following program:

public class Whatzit {

public static void main(String[] args) {
int i = 10;
int k = 0;
while (i < 100) {
int j = whatzit(i);
k = k + j;
i = i * 10;
}
System.out.println("The final value is : "+k);
}

private static int whatzit(int k) {
int i = 10;
int j = 0;
while (i > 0) {
j = j + i*k;
i = i - 1;
}
return j;
}
}
What lines are in the scope of the variable i declared at line 4?
What lines are in the scope of the variable j declared at line 7?
What lines are in the scope of the variable j declared at line 16?
What is the final output of this program? Try to trace this program - don't just plug it into Eclipse and run it to see what it does. (You can do that to check your work however).

2. For the following program, give the output produced by the program:

public class ChangeParam
{
public static void main(String[] args)
{
int i = 1;
double x = 3.4;
String s = "hi!";

System.out.println(i + " " + x + " " + s);
changeUs(i, x, s);
System.out.println(i + " " + x + " " + s);
}

private static void changeUs(int j, double y, String t)
{
j = 7;
y = -1.2;
t = "there";
System.out.println(j + " " + y + " " + t);
}
}

3. Write a method that takes two Strings as parameters and returns true if the second String is the reverse of the first String. Otherwise it should return false. In addition, write a main method that tests your method for a variety of conditions where it should return false and a variety of conditions where it should return true.

4. Write a method that takes two integers as parameters and returns true if the first integer is evenly divisible by the second integer, false otherwise. For example, if the integers are the pair (55, 5) the method should return true, while if the integers are the pair (55,6) the method should return false. In addition, write a main method that tests your method for a variety of conditions where it should return true and a variety of conditions where it should return false.

5. Write a method that takes a String as input and returns a String containing the middle character of the String if the length of that String is odd. If the length of the String is even, your method should return the middle two characters. For example, if the input String is "Hello" the method should return "l" and if the input String is "Worlds" the method should return "rl". In addition, write a main method that tests your method for a variety of String values.

6. REVIEW: According to the Section Information page for the course, when is your final exam scheduled? According to the Course Policies page, how many points will you lose off your final exam if you want to leave before your exam is scheduled during finals week? Make sure any travel plans you have for the end of the semester include you being here on the scheduled date of your final exam.

Solution Preview :

Prepared by a verified Expert
JAVA Programming: Write a method that takes two strings as parameters and
Reference No:- TGS02386359

Now Priced at $20 (50% Discount)

Recommended (97%)

Rated (4.9/5)