易截截图软件、单文件、免安装、纯绿色、仅160KB

刀石头布游戏 java版

import java.util.Scanner;
public class Game{
  void welcome(){
   println("欢迎来到剪刀石头布游戏");
  }
 Choice getUserChoice(){
  println("请选择\t[1]剪刀\t[2]石头\t[3]布");
  Scanner sc= new Scanner(System.in);
  int userChoice=Integer.parseInt(sc.nextLine());
  while(userChoice>3||userChoice<1){
   println("您输入的不合法,请重新输入");
   userChoice=Integer.parseInt(sc.nextLine());
   }
  return new Choice(userChoice);
  }
 Choice getComputerChoice(){
  return new Choice((int)(3*Math.random())+1);
  }
 void showResult(Choice userChoice,Choice computerChoice){
  int re=userChoice.compareTo(computerChoice);
  if(re==0){
   println("平了!您好,您输入的是:"+userChoice.getText());
   }else if(re==1){
   println("恭喜您获胜了!您输入的是:"+userChoice.getText()+"\t电脑输入的是:"+computerChoice.getText());
   }
  else {
  println("抱歉您输了!您输入的是:"+userChoice.getText()+"\t电脑输入的是:"+computerChoice.getText());
   }
  }
  void println(String s){
   System.out.println(s);
  }
  void start(){
  welcome();
  Choice userChoice=getUserChoice();
  Choice computerChoice=getComputerChoice();
  showResult(userChoice,computerChoice);
  }
  
 public static void main(String[] args){
  new Game().start();
  }
}
class Choice{
 String s[]={"剪刀","石头","布"};
 int value;
 Choice(int a){
  value=a;
 }
 String getText(){
  return s[value-1];
 }
 // 0为 平 1为 赢 -1为 输
 int compareTo(Choice c){
  if(value==c.value){
  &nb


相关文档:

JAVA中FileHelper的一个用法

 public boolean writeXML(String content, String filename)
    {  
        String savepath;
        FileOutputStream fout;
//        log.info("content:"+content+ ......

Java的技术分类


目前JAVA2有三个版本:J2EE(企业版)、J2SE(标准版)、J2ME(微型版) 
1、J2SE(JAVA2 Standart Edition) 
JAVA2标准版 支持所有JAVA标准规范中所定义的核心类函数库和所有的JAVA基本类别。J2SE定位在客户端程序的应用上。 
2、J2EE(JAVA2 Enterprise Edition) 
......

java读取xml

package test;
import java.io.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;
import org.xml.sax.SAXException;
public class XmlTest {
 public static void main(String[] args) {
  File xmlFile=new File("test/xml.xml");
  DocumentBuilderFactory documentBuilderFactor ......

java抽象类和抽象方法

抽象类就是不能使用new方法进行实例化的类,即没有具体实例对象的类。抽象类有点类似“模板”的作用,目的是根据其格式来创建和修改新的类。对象不能由抽象类直接创建,只可以通过抽象类派生出新的子类,再由其子类来创建对象。当一个类被声明为抽象类时,要在这个类前面加上修饰符abstract。
  &nbs ......

Java实训

 我们每个学期末都会进行将近一个月的实训,这次Java实训也即将结束,我选的课题是“个人网上银行系统”,运用了Struts,Hibernate和Spring框架,通过mvc设计模式。基本所有的功能都实现了,在实训中真的学到了很多知识,之间也遇到了很多问题,但都一一得到解决。我进一步了解了Struts的运行原理,马上面临 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号