Java Reference
In-Depth Information
Identify and correct errors in the following program:
public class
Chapter7Ex9
{
9.
public static void
main(String[] args)
{
System.out.println(signum(12));
System.out.println(signum(-11));
System.out.println(signum(20.5));
System.out.println(signum(0));
}
public static int
signum(
int
x)
{
if
(x > 0)
return
1;
else if
(x == 0)
return
0;
else
return
-1;
}
}
Find and correct error(s) in the following method definition:
public static void
doubleNum(
int
x)
{
10.
return
2 * x;
}
Find and correct error(s) in the following method definition:
public static int
squareNum(
double
x)
{
11.
return
x * x;
}
12.
Consider the following program:
import
java.util.*;
public class
Chapter7Ex12
{
static
Scanner console =
new
Scanner(System.in);
public static void
main(String[] args)
{
double
num1;
double
num2;
System.out.print("Enter two integers: ");
num1 = console.nextInt();
num2 = console.nextInt();
System.out.println();
Search WWH ::
Custom Search