快上网专注成都网站设计 成都网站制作 成都网站建设
成都网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

机器人的java代码 java 机器人类

Java趣味Java网络机器人

package auto;import *;import java sql *;import java io *;import java util *;//import db *;public class test extends Thread{URL weburl;String urladdr;public test(){}public test(String urladdr URL weburl){this urladdr=urladdr;this weburl=weburl;}public test(String urladdr){try{this urladdr=urladdr;//weburl=new URL(urladdr);this start();}catch(Exception e){System out println(e toString());}}public InputStream getStream(String url){try{//urladdr=url;URL tempurl=new URL(url);return tempurl openStream();}catch(Exception e){System out println( hello );}return null;}public void run(){while(true){ try{getStream(urladdr);Thread sleep( );}catch(Exception e){}}}public String getStr(InputStream in){try{StringBuffer temp=null;BufferedReader buffer=new BufferedReader(new InputStreamReader(in));String tempstr= ;String strsum= ;while ((tempstr=buffer readLine())!=null){strsum=strsum+tempstr;}buffer close();//in close();return strsum;}catch(Exception e){System out println( shit );}return ;}public String getMTVURL(String ){ try{String temp= substring( lastIndexOf( / )+ );temp=temp substring( temp indexOf( \ ));temp= ?Id= ;+temp;temp=temp trim();return temp; }catch(Exception e){System out println(e toString());}return null;}public String getMTVname(String ){try{String temp= substring( indexOf( 作品名 )+ );temp=temp substring( temp indexOf( ));temp=temp trim();return temp;}catch(Exception e){System out println( hello );}return null;}public void insertdb(String MTVURL String MTVname){// DBoperate writer=new DBoperate();// String insert= insert into mtvList(mtvname mtvurl)values( +MTVname+ +MTVURL+ ) ;// writer exesql(insert);}public void getover(){InputStream in=getStream(urladdr);String content=getStr(in);String url=getMTVURL(content);String name=getMTVname(content);insertdb(url name);}public static void main(String[] avg){for(;;){try{test look=new test( ;);look getStream(look urladdr) close();Thread sleep( );}catch(Exception e){System out println(e toString());continue;}}}} lishixinzhi/Article/program/Java/hx/201311/26768

创新互联公司成立与2013年,是专业互联网技术服务公司,拥有项目网站设计、成都做网站网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元博白做网站,已为上家服务,为博白各地企业和个人服务,联系电话:028-86922220

求JAVA人机猜拳的代码,类似一下界面。

自己纯手打,老半天才弄出来啊

import java.awt.BorderLayout;

import java.awt.Dimension;

import java.awt.GridBagConstraints;

import java.awt.GridBagLayout;

import java.awt.event.ActionEvent;

import java.util.Random;

import javax.swing.AbstractAction;

import javax.swing.Box;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JPanel;

import javax.swing.JTextField;

public class Demo2 extends JFrame {

private JLabel lb1, lb2, lb3, lb4; // 提示标签

private JTextField ta1, ta2;// 两个文本框

private JButton b1, b2, b3; // 三个按钮

private JPanel p1, p2; // 两个JPanel面板

public Demo2() {

// 初始化所有组件

lb1 = new JLabel("欢迎使用人机猜拳程序");

lb2 = new JLabel("你出拳: ");

lb3 = new JLabel("电脑出拳:");

lb4 = new JLabel("结果");

ta1 = new JTextField();

ta1.setPreferredSize(new Dimension(60, 60)); // 设置大小

ta1.setEditable(false);//设置不可编辑

ta2 = new JTextField();

ta2.setPreferredSize(new Dimension(60, 60));

ta2.setEditable(false);//设置不可编辑

b1 = new JButton("剪刀");

b2 = new JButton("石头");

b3 = new JButton("布");

p1 = new JPanel();

p2 = new JPanel();

// 设置第一个面板内容

Box box = Box.createVerticalBox();

Box box1 = Box.createHorizontalBox();

box1.add(lb2);

box1.add(ta1);

box1.add(lb3);

box1.add(ta2);

box.add(lb1);

box.add(Box.createVerticalStrut(40));

box.add(box1);

box.add(Box.createVerticalStrut(10));

box.add(lb4);

box.add(new JLabel());

p1.add(box);

// 设置第二个面板

p2.setLayout(new GridBagLayout()); // 使用GridBagLayout布局管理器

p2.setPreferredSize(new Dimension(0, 60));

GridBagConstraints g2 = new GridBagConstraints();

g2.fill = GridBagConstraints.BOTH;

g2.weightx = 1.0;

g2.weighty = 1.0;

g2.gridx = 0;

g2.gridy = 0;

p2.add(b1, g2);

g2.gridx = 1;

p2.add(b2, g2);

g2.gridx = 2;

p2.add(b3, g2);

//为3个按钮添加事件

b1.addActionListener(new buttonAction());

b2.addActionListener(new buttonAction());

b3.addActionListener(new buttonAction());

this.getContentPane().add(p1);

this.getContentPane().add(p2, BorderLayout.SOUTH);

this.setTitle("机器人猜拳游戏");

this.setSize(300, 300);

this.setVisible(true);

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

//事件类

class buttonAction extends AbstractAction{

@Override

public void actionPerformed(ActionEvent e) {

if(e.getSource()==b1){

ta1.setText("剪刀");

init(ta1.getText());

}else if(e.getSource()==b2){

ta1.setText("石头");

init(ta1.getText());

}else if(e.getSource()==b3){

ta1.setText("布");

init(ta1.getText());

}

}

// 模拟电脑出拳,产生三个随机数。0代表剪刀,1代表石头,2代表布

public String getQuan(){

String str="";

int num=new Random().nextInt(3) ;

if(num==0){

str="剪刀";

}else if(num==1){

str="石头";

}else if(num==2){

str="布";

}

return str;

}

// 判断输赢方法

public String isying(String s1,String s2){

String s="";

if(s1.equals(s2)){

s="平局";

}else if(s1.equals("剪刀")s2.equals("布")){

s="你赢";

}else if(s1.equals("石头")s2.equals("剪刀")){

s="你赢";

}else if(s1.equals("布")s2.equals("石头")){

s="你赢";

}else{

s="电脑赢";

}

return s;

}

public void init(String wo){

String sy=""; // 保存输赢结果

String dncq=getQuan(); //电脑出拳

if(wo.equals(dncq)){

sy="平局";

}else if(wo.equals("剪刀")dncq.equals("布")){

sy="你赢";

}else if(wo.equals("石头")dncq.equals("剪刀")){

sy="你赢";

}else if(wo.equals("布")dncq.equals("石头")){

sy="你赢";

}else{

sy="电脑赢";

}

ta2.setText(dncq);// 电脑出拳

lb4.setText("结果:"+sy);

}

}

public static void main(String[] args) {

new Demo2();

}

}

乞求大神荣光!!机器人的JAVA代码。

public class Bot {

private ArrayListString commands;

public Bot(){

commands = new ArrayList();

}

public ArrayListString getCommands(){

return commands;

}

public static void main(String[ ] args){

Bot bot = new Bot();

Scanner sc = new Scanner(System.in);

System.out.println("请输入一个整数:");

int n = sc.nextInt();

int i = 0;

String command;

sc.nextLine();

while (i n){

command = sc.nextLine();

if (!isCorrectCommand(command)){

System.out.println("每条指令只由L、R和数字组成(数字是0~100之间的整数)。");

}else if (command.length() 256){

System.out.println("每条指令的长度不超过256个字符。");

} else{

bot.getCommands().add(command);

i++;

}

}

i = 0;

while (i n){

System.out.printf("%.2f",bot.go(i));

i++;

}

}

public double go(int index){

int direction = 2;

double x = 0;

double y = 0;

String command = commands.get(index);

String str="0";

int i = 0;

char temp;

while (i command.length()){

temp = command.charAt(i);

if (temp = 47 temp = 57){

str += temp;

}else if (temp == 'L'){

int length = Integer.parseInt(str);

switch(direction){

case 1: x = x - length;break;

case 2: y = y + length;break;

case 3: x = x + length;break;

case 4: y = y - length;break;

}

str = "0";

direction = (direction - 1)%4;

if (direction == 0){

direction = 4;

}

}else{

int length = Integer.parseInt(str);

switch(direction){

case 1: x = x - length;break;

case 2: y = y + length;break;

case 3: x = x + length;break;

case 4: y = y - length;break;

}

str = "0";

direction = (direction + 1)%4;

}

i++;

}

int length = Integer.parseInt(str);

switch(direction){

case 1: x = x - length;break;

case 2: y = y + length;break;

case 3: x = x + length;break;

case 4: y = y - length;break;

}

return Math.sqrt(x * x + y * y);

}

public static boolean isCorrectCommand(String command){

Pattern pt = Pattern.compile("(?:L\\d{1,3}|R\\d{1,3}|\\d{1,3})+");

if (pt.matcher(command).matches()){

return true;

}

return false;

}

}

怎样用Java程序编写一个聊天机器人(自动和人聊天的程序)

是这样的错误么?

Frist.java:5: cannot resolve symbol

symbol : class Scanner

location: class Frist

Scanner input=new Scanner(System.in);

Scanner是JDK1.5开始才有的

这样的错误是因为JDK版本不够,不支持。。。

我用的就是1.4.2 所以是这样的错误


文章名称:机器人的java代码 java 机器人类
URL标题:http://6mz.cn/article/docsedg.html

其他资讯