我需要将 3 个单独的 Java 练习(类)放在一个类中。有人可以告诉我怎么做吗?谢谢!以下是程序:
--
public class Chapter3Exercise1
{
public static void main(String[] args)
{
printNumbers(15);
System.out.println();
printNumbers(5);
}
public static void printNumbers(int x)
{
for (int i = 1; i <= x; i++)
{
System.out.print(("[") + (i) + ("]") + (" "));
}
}
}
public class Chapter3Exercise4
{
public static void main(String[] args)
{
System.out.print(largerAbsVal(11, 2));
System.out.println();
System.out.print(largerAbsVal(4, -5));
}
public static int largerAbsVal(int x, int y)
{
return Math.max(Math.abs(x), Math.abs(y));
}
}
public class Chapter3Exercise5
{
public static void main(String[] args)
{
System.out.print(largestAbsVal(7, -2, -11));
System.out.println();
System.out.print(largestAbsVal(-4, 5, 2));
}
public static int largestAbsVal(int x, int y, int z)
{
int abs1 = Math.max(Math.abs(x), Math.abs(y));
int abs2 = Math.max(Math.abs(y), Math.abs(z));
return Math.max(abs1, abs2);
}
}
--