使用Java代码块写一个1-5数字平方的表格
时间: 2023-05-23 16:04:23 浏览: 61
Sure, here's an example Java code block that generates a table of squares for integers 1 to 5:
```
public class SquareTable {
public static void main(String[] args) {
System.out.println("Number\tSquare");
for (int i = 1; i <= 5; i++) {
int square = i * i;
System.out.println(i + "\t" + square);
}
}
}
```
This code block defines a `SquareTable` class with a `main` method that prints a header for the table with the column names "Number" and "Square". It then uses a `for` loop to iterate through integers 1 to 5 and calculate the corresponding square value (which it stores in the `square` variable). Finally, it prints each number and its corresponding square value, separated by a tab character, using the `System.out.println` method. The output of this code block should look something like this:
```
Number Square
1 1
2 4
3 9
4 16
5 25
```