|
Question Details:
1. For each of the following tasks, design a class (i.e., static)
method heading with an appropriate name, parameters, and return
type (or void). You do not need to write the method body. For
example, the heading for a method that computes and returns the
largest of two real numbers could be something like this
private static double max(double x, double y).
- The task is to convert a given integer grade (0..100) into a
corresponding letter grade.
- The task is to compute the state tax on an item, given the
cost of the item and the tax rate.
- Given three names, the task is to output them in aphabetical
order.
- Given a sentence, the task is to print each word in the sentence
on a separate line of output.
- Given a string and a character, the task is return the string
obtained by removing all occurrences of the given character from
the given string.
2.
- What is the output produced by the following programs?
-
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);
}
}
-
public class TraceMe
{
public static void main(String[] args)
{
printBox(5, 3);
}
private static void printBox(int rows, int columns)
{
int i = 0;
while (i < rows)
{
int j = 0;
while (j < columns)
{
if ((i % 2) == (j % 2))
{
System.out.print('A');
}
else
{
System.out.print('B');
}
j = j + 1;
}
System.out.println();
i = i + 1;
}
}
}
-
public class ItsAMistery
{
public static void main(String[] args)
{
mistery("123456789");
}
private static void mistery(String str)
{
int i = 0;
while (i < str.length())
{
System.out.print(str.charAt((i + 5) % str.length()));
i = i + 1;
}
}
}
|