public static void main(String[] args) {
StringBuilder buffer = new StringBuilder();
// title
for (int i = 1; i <= 5; i++) {
buffer.append(i + "\t" + 10*i + "\t" + 100*i + "\t" + 1000*i + "\n");
}
System.out.println(buffer.toString());
}
// 比较简单,呵呵,直接写了
public class Test {
public static void print(int line) {
StringBuilder buffer = new StringBuilder();
// title
buffer.append("N\t10*N\t100*N\t1000*N").append("\n");
for (int i = 0; i < line; i++) {
buffer.append(i).append("\t").append(10*i).append("\t")
.append(100*i).append("\t").append(1000*i).append("\n");
}
System.out.println(buffer.toString());
}
public static void main(String[] args) {
print(5);
}
}
---------------------------------------------------------------
简单点直接这样写:
public class Test {
public static void main(String[] args) {
System.out.println ("N\t10*N\t100*N\t1000*N\n");
for (int i = 0; i < 5; i++) {
System.out.print(i);
System.out.print("\t");
System.out.print(10*i);
System.out.print("\t");
System.out.print(100*i);
System.out.print("\t")
System.out.println(1000*i)
}
}
不需要用户输入?只要这五行?
int num=5;
for(int i=1;i<=num;i++){
System.out.println(i+"\t"+(i*10)+"\t"+(i*100)+"\t"+(i*1000));
}
package test;
import java.util.Scanner;
public class Test06 {
public static void main(String[] args) {
System.out.println("请输入要打印的行数:");
Scanner sc = new Scanner(System.in);
int m = sc.nextInt();
System.out.println("N" + " " + "10*N" + " " +"100*N" + " " + "1000*N");
print(m);
}
public static void print(int m) {
for(int i=1; i<=m;i++) {
System.out.println(i + " " + 10*i + " " +100*i + " " + 1000*i);
}
}
}
public class test{
public static void main(String args[]){
System.out.println("N \t 10*N \t 100*N \t 1000*N");
for(int i=1; i<=5; i++){
System.out.print(i+"\t");
System.out.print(i*10+"\t");
System.out.print(i*100+"\t");
System.out.print(i*1000+"\t");
System.out.println("");
}
}
}