package test;
import java.util.Scanner;
import java.util.Random;
public class caiquan {
public static void main(String[] args){
Game g=new Game();
g.begin();
}
//将这个类定义为静态就好了,也就说改成 static class Game
class Game{
public void begin(){
System.out.println("********************");
System.out.println("A finger-guessing game");
System.out.println("********************");
System.out.println("Start game(1/0)");
Scanner input = new Scanner(System.in);
int result = input.nextInt();
if(result==1){
System.out.println("请输入猜拳次数:");
int num = input.nextInt();
play(num);
}else{
System.out.println("Go Fuck Yourself!");
}
}
public void play(int num){
int userScore=0;//人赢的次数
int pcScore=0;//pc赢的次数
Random r = new Random();
Scanner input = new Scanner(System.in);
while(num>0){
int x = r.nextInt(100)%3+1;
System.out.println("请输入(1,剪刀 2,石头 3,布)");
int s = input.nextInt();
if(s>=4||s==0){
System.out.println("瓜娃子看不懂嗦,只能输入1,2,3!");
}
if(s==1){
switch(x){
case 1:
System.out.println("平局,你出剪刀,电脑出剪刀");
case 2:
System.out.println("你输了,你出剪刀,电脑出石头");
pcScore++;
case 3:
System.out.println("你赢了,你出剪刀,电脑出布");
userScore++;
}
}
if(s==2){
switch(x){
case 1:
System.out.println("你赢了,你出石头,电脑出剪刀");
userScore++;
break;
case 2:
System.out.println("平局,你出石头,电脑出石头");
break;
case 3:
System.out.println("你输了,你出石头,电脑出布");
pcScore++;
break;
}
}
if(s==3){
switch(x){
case 1:
System.out.println("你输了,你出布,电脑出剪刀");
pcScore++;
break;
case 2:
System.out.println("你赢了,你出布,电脑出石头");
userScore++;
break;
case 3:
System.out.println("平局,你出布,电脑出布");
break;
}
}
num--;
}
System.out.println("**************");
System.out.println("你赢了:"+userScore+"次!");
System.out.println("电脑赢了:"+pcScore+"次!");
if(userScore==pcScore){
System.out.println("平局!");
}else if(userScore>pcScore){
System.out.println("你赢了!");
}else{
System.out.println("电脑赢了!");
}
}
}
}
//在Java中,类中的静态方法不能直接调用动态方法。只有将某个内部类修饰为静态类,然后才能够在静态类中调用该类的成员变量与成员方法
Java中报错No enclosing instance of type caiquan is accessible. Must qualify the allocation with an enclosing instance of type caiquan (e.g. x.new A() where x is an instance of caiquan).的更多相关文章
-
【转】Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
最近在看Java,在编译写书上一个例子时,由于书上的代码只有一部分,于是就自己补了一个内部类.结果编译时出现:No enclosing instance of type E is accessible ...
-
Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing ...
-
No enclosing instance of type test is accessible. Must qualify the allocation with an enclosing inst
今日遇到一个报错如下: No enclosing instance of type test is accessible. Must qualify the allocation with an en ...
-
No enclosing instance of type test8 is accessible. Must qualify the allocation with an enclosing instance of type test8 (e.g. x.new A() where x is an
在编译一个例子时,结果编译时出现: No enclosing instance of type test8 is accessible. Must qualify the allocation wit ...
-
No enclosing instance of type Outer is accessible. Must qualify the allocation with an enclosing instance of type Outer (e.g. x.new A() where x is an instance of Outer)
之前看内部类的时候没发现这个问题,今天写代码的时候遇到,写个最简单的例子: 下面这一段代码 红色的部分就是编译报错: No enclosing instance of type Outer is ac ...
-
No enclosing instance of type Test is accessible. Must qualify the allocation with an enclosing instance of type Test (e.g. x.new A() where x is an instance of Test).
Java编写代码过程中遇到了一个问题,main方法中创建内部类的实例时,编译阶段出现错误,查看错误描述: No enclosing instance of type Test is accessibl ...
-
【eclipse】No enclosing instance of type A is accessible. Must qualify the allocation with an enclosing instance of type A
用 eclipse 写 Java 代码时出现了这个问题,详细如下: No enclosing instance of type TestParsingLinkedList is accessible. ...
-
No enclosing instance of type Demo is accessible. Must qualify the allocation with an enclosing instance of type Demo (e.g. x.new A() where x is an instance of Demo).
No enclosing instance of type Demo is accessible. Must qualify the allocation with an enclosing inst ...
-
No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
在Java中,类中的静态方法不能直接调用动态方法.只有将某个内部类修饰为静态类,然后才能够在静态类中调用该类的成员变量与成员方法.所以在不做其他变动的情况下,最简单的解决办法是将public clas ...
随机推荐
-
代码高亮插件SyntaxHighlighter
http://alexgorbatchev.com/SyntaxHighlighter/download/
-
GDC2016 Epic Games【Bullet Train】 新风格的VR-FPS的制作方法
追求“舒适”和“快感”的VR游戏设计方法 http://game.watch.impress.co.jp/docs/news/20160318_749016.html [Bullet Tr ...
-
Kerberos ticket lifetime及其它
前言 之前的博文中涉及到了Kerberos的内容,这里对Kerberos ticket lifetime相关的内容做一个补充. ticket lifetime Kerberos ticket具有lif ...
-
怎样将某一类型标识为适合绑定到 System.Web.UI.WebControls.ObjectDataSource 对象的对象
1.页面的代码如下: body> <form id="form1" runat="server"> <div> </div& ...
-
掌握 Ajax,第 2 部分: 使用 JavaScript 和 Ajax 发出异步请求
转http://www.ibm.com/developerworks/cn/xml/wa-ajaxintro2/ 掌握 Ajax,第 2 部分: 使用 JavaScript 和 Ajax 发出异步请求 ...
-
video标签 拖动 转自w3school
调整视频大小 播放 暂停 用js实现 详细参见http://www.w3school.com.cn/tiy/t.asp?f=html5_video_dom 图片的拖动详见http://www.w3sc ...
-
IDEA 无法运行Junit, 报错Class not found xxxx Empty test suite.
网上搜了一圈没找到答案, 最后才发现是因为testmodule没有把class编译到主代码编译的路径.
-
python开发concurent.furtrue模块:concurent.furtrue的多进程与多线程&;协程
一,concurent.furtrue进程池和线程池 1.1 concurent.furtrue 开启进程,多进程&线程,多线程 # concurrent.futures创建并行的任务 # 进 ...
-
CSS选择器之基本选择器总结
一.元素选择器(所有浏览器支持) 元素选择器(标签名选择器)其实就是文档的元素,如html,body,p,div等等, 下面例子中选择了span元素,并设置了字体颜色为红色. <body> ...
-
jconsole 连接 wildfly 10 监控
1,远程wildfly服务器: 访问:http://211.100.75.242:9990 按照提示添加用户,重启后可以登录进入.成功. 2,省事做法.本地解压wildfly服务器,进入wildfly ...