用Java编程两道简单的题回答出来追加悬赏

1、容器中加俩个按钮,单击按钮这个事件进行处理,若有个多个按钮时,单击时,怎么区分单击的是哪一个,要求使用paint、repaint、actionperform(以圆变成月亮为例)
2、通过随机数,产生n个随机数,找出最大值、最小值。。。
怎么没人回答呢?很难?

第1个回答  2011-06-26
第一道不明白你的意思
第二道看代码
Random random = new Random();
int min = Integer.MAX_VALUE;
int max = Integer.MIN_VALUE;
//随机产生总共要随机的数量 (我内存不够大,这里我限制了最多100个)
int length = random.nextInt(100);
int[] ranArr = new int[length];
//产生所有随机数
for(int ran : ranArr) {
ran = random.nextInt();
//找最小值
if(ran < min) {
min = ran;
}
//找最大值
if(ran > max) {
max = ran;
}
System.out.println(ran);
}
System.out.println("最小值:" + min);
System.out.println("最大值:" + max);
第2个回答  2011-06-27
先给你第二题,我以前做过的,题目跟你的差不多。先看看喽!
使用java.lang,Math类,生成100个0-99的随机整数,找出它们之中的最大者及最小者,并统计大于50的整数个数。
程序如下:
package src;
public class Text {
public static void main(String[] args) {
int a[] = new int[100];
int i,num=0,count=0;
System.out.println("100以内的100个随机数为:");
for (i=0;i<100;i++){
num = (int)(Math.random()*100-1);
a[i]=num;
System.out.print(a[i]+" ");}

if(a.length > 0){
int index = 0;
int b = a[0];
for(int j=0; j<a.length; j++){
if(a[j] > b){
b = a[j];
index = j;
}
}

System.out.println("\n\n数组中最大值是"+b+",下标是"+index);
}
if(a.length > 0){
int index = 0;
int b = a[0];
for(int j=0; j<a.length; j++){
if(a[j] < b){
b = a[j];
index = j;
}
}

System.out.println("\n\n数组中最小值是"+b+",下标是"+index);
}
for(i=0;i<100;i++){
if(a[i]>50){count ++;}
continue;
}
System.out.print("\n\n大于50的总个数为:"+count);

}

}
第3个回答  2011-06-27
给你第一个的代码,我做了个相当简单的程序,能满足你说的要求
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import javax.swing.*;

public class doNumber {

private static Text text;
/**
* Launch the application
* @param args
*/
public static void main(String[] args) {
final Display display = Display.getDefault();
final Shell shell = new Shell();
shell.setSize(437, 241);
shell.setText("SWT Application");
//
final Group group = new Group(shell, SWT.NONE);
group.setText("您输入的数字是");
group.setBounds(54, 10, 305, 154);

text = new Text(group, SWT.BORDER);
text.setBounds(35, 31, 224, 72);
String input=JOptionPane.showInputDialog("请输入数字");
int num=Integer.parseInt(input);
if (num>=200){
JOptionPane.showMessageDialog(null, "输入的数字大于200,是否继续?");
text.setText(input);
}
else
{
text.setText(input);
}

shell.open();

while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
private static String String(int num) {
// TODO 自动生成方法存根
return null;
}

}
本回答被提问者采纳