package com.derek
import java.util.HashMap
public class ComputerPerson {
private int var
public ComputerPerson(int var){
this.var = var
}
public String addComputer(){
HashMap list = new HashMap()
list.put(1,"刘备")
list.put(2,"孙权")
list.put(3,"曹 *** ")
String computer = list.get(var)
return computer
}
}
package com.derek
import java.util.HashMap
import java.util.Scanner
public class Method {
int i,j,k = 0
String name//电脑
String name1//玩家
public Method(String name,String name1){
this.name = name
this.name1 = name1
}
public static int computerGame(){
int show = (int)(Math.random()*10)%3+1
return show
}
public void judge(){
HashMap list = new HashMap()
list.put(1,"剪刀")
list.put(2,"石头")
list.put(3,"布")
System.out.println(name1+" VS "+name+" 对战")
System.out.println("要开始吗?(y/n)")
Scanner sc = new Scanner(System.in)
String str = sc.next()
if(str.equals("n")){
System.exit(0)
}
while(str.equals("y")){
i +=1
System.out.print("请出拳:1.剪刀 2.石头 3.布(输入相应数字):")
System.out.println()
int var = sc.nextInt()
if(var!=1&&var!=2&&var!=3){
System.out.println("你输入错误")
}else{
String com = list.get(var)
System.out.print("你出拳:"+com)
System.out.println()
int show = (int)(Math.random()*10)%3+1
System.out.println(name+"出拳:"+list.get(show))
if(var == (show+1)|| var==(show-2)){
System.out.println("^_^,你赢了")
k =+1
}else if(var == show){
System.out.println("^_^,你们平局")
}else{
System.out.println("^..^,你输了")
j =+1
}
System.out.println("是否开始下一轮(y/n):")
str = sc.next()
}
}
System.out.println(name1+" VS "+name+" 对战")
System.out.println("对战次数:"+i)
System.out.println("\n姓名\t得分")
System.out.println(name +"\t"+j)
System.out.println(name1 +"\t"+k)
}
}
package com.derek
import java.util.Scanner
public class TestPerson {
public static void main( String[] args){
System.out.println("\t\t****************")
System.out.println("\t\t** 猜拳,开始 **")
System.out.println("\t\t***************\n")
System.out.println("出拳规则:1、剪刀 2、石头 3、布")
Scanner sc = new Scanner(System.in)
System.out.println("请选择对方角色(1:刘备 2:孙权 3:曹 *** ):")
int a = sc.nextInt()
ComputerPerson computerPerson = new ComputerPerson(a)
System.out.println("请输入你的姓名:")
String b = sc.next()
Method method = new Method(computerPerson.addComputer(),b)
method.judge()
}
}
System.in.skip(2)这样就可以了 因为你输入后 按回车其实是两个字符 \r\n 所以应该跳过两个不信你可以在 total = total + 0
这个后面 加上两个 System.out.println(System.in.read())看看 肯定是打印两个值
您好,
估计您在命令行执行了类似:"java Test.java" 的命令。
请试一下:"java Test"。
1、首先确认 javac 编译之后确实生成了 class 文件。
2、执行calss文件时确认执行路径无误。并输入 “java 文件名”。
报错内容,想见图解。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)