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).
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 ...
随机推荐
- 前端模块化开发学习之gulp&browserify篇
随着web应用的发展,前端的比重占得越来越多,编写代码从而也越来越复杂.而通常我们需要将不同功能或者不同模块的代码分开写,最后在html中一起加载,这样做是可以的,但是当你需要进行维护或者是二次开发 ...
- KEIL、uVision、RealView、MDK、KEIL C51区别比较
KEIL uVision,KEIL MDK,KEIL For ARM,RealView MDK,KEIL C51,KEIL C166,KEIL C251 从接触MCS-51单片机开始,我们就知道有一个 ...
- time.h
目录 1简介 2代码示例 3从系统时钟获取时间方式 4time函数介绍 函数名称: localtime 函数名称: asctime 函数名称: ctime 函数名称: difftime 函数名称: g ...
- 为 Joomla 而生的 Kunena 论坛安装手册
查看并下载最新版本Kunena论坛,或直接下载Kunena1.7.2.如果你打算在Joomla网站中安装一个论坛,可以考虑一下Kunena论坛组件,一个为Joomla而生的免费的开源论坛组件. 安装: ...
- 《A First Course in Probability》-chaper5-连续型随机变量-随机变量函数的分布
在讨论连续型随机变量函数的分布时,我们从一般的情况中(讨论正态分布的文章中提及),能够得到简化版模型. 回忆利用分布函数和概率密度的关系求解随机变量函数分布的过程,有Y=g(x),如果g(x)是严格单 ...
- 宁波Uber优步司机奖励政策(2月1日~2月7日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- java使用batik转换svg文件
svg是一种矢量图片格式,用来保存高保真的图片.我们可以用编辑器打开svg,我们可以看到svg文件其实就是一个xml文件,这种文件浏览器也可以识别.因此要查看svg用现成的浏览器就可以了.值得庆幸的是 ...
- ORA-01502: 索引或这类索引的分区处于不可用状态
ORA-01502: 索引或这类索引的分区处于不可用状态 原因: 出现这个问题,可能有人move过表,或者disable 过索引.1. alter table xxxxxx move tablespa ...
- 【BZOJ-1901】Dynamic Rankings 带修主席树
1901: Zju2112 Dynamic Rankings Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 7292 Solved: 3038[Su ...
- 【python自动化第一篇:python介绍与入门】
一.python介绍以及发展史 1.1 python的介绍: 简单点来说吧,python这玩意儿是一个叫做Guido van Rossum的程序猿在1989年的圣诞打发时间而决心去开发的一个脚本编程 ...