1:编写程序,输出以下数据:
N 10N 100N 1000N
1 10 100 1000
2 20 200 2000
3 30 300 3000
4 40 400 4000
5 50 500 5000我的程序是:class NNN
{
public static void main(String args[])
{
int i,j;
int a[][]=new int[5][4];
for(i=0;i<=5;i++)
{
for(j=0;j<4;j++)
{
if(i==0)
{
a[0][j]=N*power(10,j); //这里有问题
}
else
a[i][j]=i*power(10,j);
}
}
int power(m,n) //这里也有问题?
{
power(m,1)=m;
return m*power(n-1);
}
System.out.println(a[i][j]);
}
}
N 10N 100N 1000N
1 10 100 1000
2 20 200 2000
3 30 300 3000
4 40 400 4000
5 50 500 5000我的程序是:class NNN
{
public static void main(String args[])
{
int i,j;
int a[][]=new int[5][4];
for(i=0;i<=5;i++)
{
for(j=0;j<4;j++)
{
if(i==0)
{
a[0][j]=N*power(10,j); //这里有问题
}
else
a[i][j]=i*power(10,j);
}
}
int power(m,n) //这里也有问题?
{
power(m,1)=m;
return m*power(n-1);
}
System.out.println(a[i][j]);
}
}
class NNN {
static int power(int m, int n) //这里也有问题?
{
return (int) (m * Math.pow(10, n));
} public static void main(String args[]) {
int i, j;
int a[][] = new int[5][4];
for (i = 0; i < 5; i++) {
for (j = 0; j < 4; j++) {
a[i][j] = power(i + 1, j);
}
}
for (i = 0; i < 5; i++) {
for (j = 0; j < 4; j++)
System.out.print(a[i][j] + " "); System.out.println();
}
}
}
a[0][j]=N*power(10,j); //这里有问题,
你的N在哪定义的?
int power(m,n) //这里也有问题?
m,n没定义.且你把函数定义在函数中 power(m,1)=m; // 函数是不可赋值的
return m*power(n-1); // 你定义的是二个参数的,调用时有参数只有一个
是作业题吗?
好好看书吧!
{
public static void main(String args[])
{
int i,j;
int a[][]=new int[6][4];
for (i=0;i<4;i++) System.out.print(power(10,i)+"N ");
System.out.println();
for(i=0;i<6;i++)
{
for(j=0;j<4;j++)
{
if(i==0)
{
a[0][j]=power(10,j); //这里有问题
}
else
a[i][j]=i*power(10,j);
System.out.print(a[i][j]+ " ");
}
System.out.println();
}
}
public static int power(int m,int n){
if (n==0) {
return 1;
}
else return m*power(m,n-1);
}
}
你的程序与题目不和,少了最上面的一行输出(那才是最重要的)
zebra007(呼呼) :我这样才是正确的。其实就是在你的程序上删除了几条语句。public class NNN1
{
public static void main(String args[])
{
int i,j;
int a[][]=new int[6][4];
for (i=0;i<4;i++) System.out.print(power(10,i)+"N ");
System.out.println();
for(i=1;i<6;i++) //此处从地一行开始算起,把第零行的消掉。
{
for(j=0;j<4;j++)
{ //此处多余的删除掉了
a[i][j]=i*power(10,j);
System.out.print(a[i][j]+ " ");
}
System.out.println();
}
}
public static int power(int m,int n)
{
if (n==0)
{
return 1;
}
else return m*power(m,n-1);
}
}
//1N 10N 100N 1000N
//1 10 100 1000
//2 20 200 2000
//3 30 300 3000
//4 40 400 4000
//5 50 500 5000
//Press any key to continue..
import java.awt.event.*;
import java.applet.*;public class Addition2 extends Applet implements ActionListener
{
Label label1=new Label("*");
Label label2=new Label("=");
TextField field1=new TextField(6);
TextField field2=new TextField(6);
TextField field3=new TextField(6);
Button button1=new Button("相乘");
public void init()
{
add(field1);
add(label1);
add(field2);
add(label2);
add(field3);
add(button1);
button1.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
int x=Integer.parseInt(field1.getText())*Integer.parseI(field2.getText());
field3.setText(Integer.toString(x));
}
}
{
public static void main(String[] args)
{ System.out.println("N\t10N\t100N\t1000N");
for(int i=1;i<6;i++)
{
for(int j=1;j<=1000;j=j*10)
{
int temp = i*j;
System.out.print(temp+"\t");
}
System.out.println();
}
}
}
public static void main(String[] args){
System.out.println("N 10N 100N 1000N");
System.out.println("1 10 100 1000");
System.out.println("2 20 200 2000");
System.out.println("3 30 300 3000");
System.out.println("4 40 400 4000");
System.out.println("5 50 500 5000");
}
}
public class test_NNN { /**
* @param args
*/
public static int power(int n){
if (n==1) return 10;
if (n==0) return 1;
return 10*power(n-1);
}
public static void main(String args[])
{
int i,j;
int a[][]=new int[6][4];
for(i=0;i<=5;i++)
{
for(j=0;j<4;j++)
{
if(i==0)
{
a[0][j]=power(j);
}
else
a[i][j]=i*power(j);
}
}
for (i=0;i<=5;i++){
for (j=0;j<4;j++)
if (i==0) System.out.print(a[i][j]+"N ");
else
System.out.print(a[i][j]+" ");
System.out.println();
}
}
}
输出结果OK。
public class NNN {
/**
* @param m
* @param n
* @return ad
*/
public static int power(int m,int n) {
return (int)(m*Math.pow(10, n));
}
/**
* @param args
*/
public static void main(String args[]){
int i,j;
String N;
int a[][]=new int[6][4];
for(i=0;i<=5;i++){
for(j=0;j<4;j++){
if(i==0){
System.out.print( power(10,j)+"N"+" "); //这里有问题
}
else{
a[i][j]=i*power(10,j);
System.out.print(a[i][j]+" ");
}
if(j==3){
System.out.println("");
}
}
}
}
}