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
創(chuàng)新互聯(lián)公司成立與2013年,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項目網(wǎng)站設(shè)計、成都做網(wǎng)站網(wǎng)站策劃,項目實施與項目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元博白做網(wǎng)站,已為上家服務(wù),為博白各地企業(yè)和個人服務(wù),聯(lián)系電話:028-86922220
自己純手打,老半天才弄出來啊
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; // 提示標(biāo)簽
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("結(jié)果");
ta1 = new JTextField();
ta1.setPreferredSize(new Dimension(60, 60)); // 設(shè)置大小
ta1.setEditable(false);//設(shè)置不可編輯
ta2 = new JTextField();
ta2.setPreferredSize(new Dimension(60, 60));
ta2.setEditable(false);//設(shè)置不可編輯
b1 = new JButton("剪刀");
b2 = new JButton("石頭");
b3 = new JButton("布");
p1 = new JPanel();
p2 = new JPanel();
// 設(shè)置第一個面板內(nèi)容
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);
// 設(shè)置第二個面板
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());
}
}
// 模擬電腦出拳,產(chǎn)生三個隨機數(shù)。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=""; // 保存輸贏結(jié)果
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("結(jié)果:"+sy);
}
}
public static void main(String[] args) {
new Demo2();
}
}
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("請輸入一個整數(shù):");
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和數(shù)字組成(數(shù)字是0~100之間的整數(shù))。");
}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;
}
}
是這樣的錯誤么?
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網(wǎng)址:http://www.muchs.cn/article16/docsedg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供商城網(wǎng)站、用戶體驗、標(biāo)簽優(yōu)化、網(wǎng)站制作、App設(shè)計、移動網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)