123456789101112131415161718192021public static Geocache[] createGeocaches(int a) { if(a = 0) return new Geocache[0]; Random rand = new Random(); Geocache[] result = new Geocache[a]; for(int i = 0; i a; i++) { //因为题目没有描述,这里假设x, y是随机整数,Geocache有a href=";tn=44039180_cprfenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1dhrjIWn1D4n19hmWDzm1R0IAYqnWm3PW64rj0d0AP8IA3qPjfsn1bkrjKxmLKz0ZNzUjdCIZwsrBtEXh9GuA7EQhF9pywdQhPEUiqkIyN1IA-EUBtkPWm4rjR4rHbLPWR1nH63P16L" target="_blank" class="baidu-highlight"构造函数/a(int, int) int x = rand.nextInt(); int y = rand.nextInt(); result[i] = new Geocache(x, y); } return result; }
成都创新互联公司专注于企业成都全网营销、网站重做改版、赛罕网站定制设计、自适应品牌网站建设、H5建站、商城开发、集团公司官网建设、外贸网站制作、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为赛罕等各大城市提供网站开发制作服务。
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Calculator extends JFrame {
private Container container;
private GridBagLayout layout;
private GridBagConstraints constraints;
private JTextField displayField;
private String lastCommand;
private double result;
private boolean start;
public Calculator() {
super("Calculator");
container=getContentPane();
layout=new GridBagLayout();
container.setLayout(layout);
constraints=new GridBagConstraints();
start=true;
result=0;
lastCommand = "=";
displayField=new JTextField(20);
displayField.setHorizontalAlignment(JTextField.RIGHT);
constraints.gridx=0;
constraints.gridy=0;
constraints.gridwidth=4;
constraints.gridheight=1;
constraints.fill=GridBagConstraints.BOTH;
constraints.weightx=100;
constraints.weighty=100;
layout.setConstraints(displayField,constraints);
container.add(displayField);
ActionListener insert = new InsertAction();
ActionListener command = new CommandAction();
addButton("Backspace",0,1,2,1,insert);
addButton("CE",2,1,1,1,insert);
addButton("C",3,1,1,1,insert);
addButton("7",0,2,1,1,insert);
addButton("8",1,2,1,1,insert);
addButton("9",2,2,1,1,insert);
addButton("/",3,2,1,1,command);
addButton("4",0,3,1,1,insert);
addButton("5",1,3,1,1,insert);
addButton("6",2,3,1,1,insert);
addButton("*",3,3,1,1,command);
addButton("1",0,4,1,1,insert);
addButton("2",1,4,1,1,insert);
addButton("3",2,4,1,1,insert);
addButton("-",3,4,1,1,command);
addButton("0",0,5,1,1,insert);
addButton("+/-",1,5,1,1,insert);
addButton(".",2,5,1,1,insert);
addButton("+",3,5,1,1,command);
addButton("=",0,6,4,1,command);
setSize(300,300);
setVisible(true);
}
private void addButton(String label,int row,int column,int with,int height,ActionListener listener) {
JButton button=new JButton(label);
constraints.gridx=row;
constraints.gridy=column;
constraints.gridwidth=with;
constraints.gridheight=height;
constraints.fill=GridBagConstraints.BOTH;
button.addActionListener(listener);
layout.setConstraints(button,constraints);
container.add(button);
}
private class InsertAction implements ActionListener {
public void actionPerformed(ActionEvent event) {
String input=event.getActionCommand();
if (start) {
displayField.setText("");
start=false;
if(input.equals("+/-"))
displayField.setText(displayField.getText()+"-");
}
if(!input.equals("+/-")) {
if(input.equals("Backspace")) {
String str=displayField.getText();
if(str.length()0)
displayField.setText(str.substring(0,str.length()-1));
}else if(input.equals("CE")||input.equals("C")) {
displayField.setText("0");
start=true;
}else
displayField.setText(displayField.getText()+input);
}
}
}
private class CommandAction implements ActionListener {
public void actionPerformed(ActionEvent evt) {
String command=evt.getActionCommand();
if(start) {
lastCommand=command;
}else {
calculate(Double.parseDouble(displayField.getText()));
lastCommand=command;
start=true;
}
}
}
public void calculate(double x) {
if (lastCommand.equals("+")) result+= x;
else if (lastCommand.equals("-")) result-=x;
else if (lastCommand.equals("*")) result*=x;
else if (lastCommand.equals("/")) result/=x;
else if (lastCommand.equals("=")) result=x;
displayField.setText(""+ result);
}
public static void main(String []args) {
Calculator calculator=new Calculator();
calculator.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
JAVA不熟,不过算法都差不多。
等会给你个C/C++的。
我用C++做出来了.
基本思路说下:
先定义类
class JiuGong
{
public:
int table[9][9];//这个是九宫里的数学 不知道的用0代替
bool mark[9][9];//这个表示九宫状态,true表示已知的,可以不计算的
int x;
int y;//x,y表示当前正在试验的点
JiuGong *pre;//这是后面堆栈用的
bool check();//这函数进行九宫检查,包括行/列/小九宫的查错
bool finish();//这函数检查是否已经完成
bool find();//这函数用来找到下一个未知点(试验点)位置
}
再定义一个类 这是个堆栈
class JiuGongStack()
{
public:
JiuGong *top;
bool push(JiuGong *p);//压
bool pop(JiuGong *p);//弹
}
推算过程:
先声明一个JiuGong结构,导入初始值.
用成员函数find()找到第一个未知点.
以下循环:
{
在试验点数字加1
用成员函数finish()检查是否结束
Y- 成功 返回
N- 向下
检查数字9
Y-POP -POP失败 -题目错误 返回
N-向下
用成员函数check()查错
无错-PUSH
错-继续循环
}
完毕.
import java.util.*;
public class HelpTest {
public static void main(String[] args) {
Random suijishu = new Random();
Scanner saomiaoyi = new Scanner(System.in);
System.out.println("请输入个数:");
int timu = saomiaoyi.nextInt();
int[][] da = new int[timu][timu];//定义数组时未使用数组长度,随机数3导致数组越界
timu = da.length;
for (int a = 0; a timu; a++) {
for (int i = 0; i timu; i++) {
da[a][i] = suijishu.nextInt(timu) + 1;
}
}
for (int b = 0; b timu; b++) {
for (int c = 0; c timu; c++) {
System.out.println(da[b][c]);
}
}
}
}
这个是更改过的你对比对比,然后class文件名 不要用中文,用英文,每个单词首字母大写