第二章第十八题(打印表格)(Print a table)

    科技2022-07-10  164

    第二章第十八题(打印表格)(Print a table)

    2.18(打印表格)编写程序,显示下面的表格。将浮点数值类型转换为整数。 abpow(a,b)12123834814510245615625

    2.18(Print a table) Write a program that displays the following table.convert double to int.

    abpow(a,b)12123834814510245615625 参考代码: package chapter02; public class Code_18 { public static void main(String[] args) { int a,b,PowerResult; System.out.println("a b pow(a,b)"); a = 1;b = 2;PowerResult = (int)Math.pow(a,b); System.out.println(a + " " + b + " " + PowerResult); a = 2;b = 3;PowerResult = (int)Math.pow(a,b); System.out.println(a + " " + b + " " + PowerResult); a = 3;b = 4;PowerResult = (int)Math.pow(a,b); System.out.println(a + " " + b + " " + PowerResult); a = 4;b = 5;PowerResult = (int)Math.pow(a,b); System.out.println(a + " " + b + " " + PowerResult); a = 5;b = 6;PowerResult = (int)Math.pow(a,b); System.out.println(a + " " + b + " " + PowerResult); } } 结果显示: a b pow(a,b) 1 2 1 2 3 8 3 4 81 4 5 1024 5 6 15625 Process finished with exit code 0
    Processed: 0.009, SQL: 8