‘壹’ 甯蹇椤啓涓涓狢 璇瑷浠1 + 鍒10 镄勫皬绋嫔簭銆
#include<stdio.h>
void main()
{
int i,N,a=0;
printf("璇疯緭鍏N=");
scanf("%d",&N);
for(i=1;i<=N;i++)
a+=i;
printf("鍦ㄤ粠1鍒10閲屽墠%d涓鏁板瓧镄勬诲拰涓:%d",N,a);
}
‘贰’ 用java编写一个彩票抽奖程序
我写给你,如果是本专业,以后要多多学习。JDK 1.6
import java.awt.GridLayout;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Iterator;
import java.util.Random;
import java.util.Set;
import java.util.TreeSet;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;
public class LuckyDrawn {
private JFrame f = new JFrame("Lucky Drawn");
private JButton btn = new JButton("Drawn");
private JTextField result = new JTextField("Result");
private static final int MIN = 1;
private static final int MAX = 30;
private static final int RESULT_COUNT = 7;
public LuckyDrawn(){
f.add(btn);
f.add(result);
result.setEditable(false);
btn.addMouseListener(new MouseListener(){
public void mouseClicked(MouseEvent e) {
Random rand = new Random();
Set<Integer> set = new TreeSet<Integer>();
while(set.size() < RESULT_COUNT){
set.add(new Integer(rand.nextInt(MAX)+ 1));
}
StringBuffer sb = new StringBuffer("Lucky numbers are: ");
for (Iterator iter = set.iterator(); iter.hasNext();) {
sb.append(((Integer) iter.next()).intValue()).append(", ");
}
result.setText(sb.substring(0, sb.length() - 2).toString());
f.pack();
}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mousePressed(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
});
f.setLayout(new GridLayout(2, 1));
f.setVisible(true);
f.setLocation(500, 200);
f.pack();
f.validate();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new LuckyDrawn();
}
}