急!!帮我写一下JAVA小程序,谢谢,

2024-11-23 04:20:01
推荐回答(6个)
回答1:

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());
}

回答2:

// 比较简单,呵呵,直接写了
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)
}
}

回答3:

不需要用户输入?只要这五行?

回答4:

int num=5;
for(int i=1;i<=num;i++){
System.out.println(i+"\t"+(i*10)+"\t"+(i*100)+"\t"+(i*1000));
}

回答5:

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);
}
}
}

回答6:

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("");
    }
   }
}