站内搜索: 请输入搜索关键词

当前页面: 开发资料首页J2SE 专题如何实现这个问题?

如何实现这个问题?

摘要: 如何实现这个问题?


public class Square3{
public static void main(String args[]){
System.out.print("请输入一个整数:");
System.out.println(args[0]);
String nStr=args[0];
int n=Integer.parseInt(nStr);
int nn=n*n;
int nnn=n*n*n;
int nnnn=n*n*n*n;
System.out.println(n+"的平方是:"+nn);
System.out.println(n+"的三次方是:"+nnn);
System.out.println(n+"的四次方是:"+nnnn);
}
}
上面的这段代码编译要java Square3 3才能得到结果。
我想问的是,怎么才能让程序先输出“请输入一个整数:”然后我再填一个数字,得到最后的结果。


用线程的wait()方法就可以了
还要注意这个程序要做try...catch


/*
* Created on 2006-9-27
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package com.pss.test.sep;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import com.pss.util.prints.Conica;

/**
* @author Administrator
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class Test2 {

public static void main(String[] args) throws Exception{
Conica.pl("Please input a number, then press Enter..");
BufferedReader keyin=new BufferedReader(new InputStreamReader(System.in));

String s = keyin.readLine();
try {
int n = Integer.parseInt(s);
System.out.println(n + "的平方是:" + (int)Math.pow(n, 2));
System.out.println(n + "的三次方是:" + (int)Math.pow(n, 3));
System.out.println(n + "的四次方是:" + (int)Math.pow(n, 4));
} catch (Exception ex) {
Conica.pl("Invalid number.");
}
Conica.pl("I love java!");
}
}



看不懂啊。。伤心中!
谢谢你啊。。呵呵。。


↑返回目录
前一篇: java中有没有把class直接转化为byte数组的方法?
后一篇: 怎么实现填充颜色的渐变效果??????