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 ...
 
随机推荐
- How to install Apache Server on Windows
			
Note Those of you interested in the Apache 2.0.X tutorial, it has been abandon and I will no longer ...
 - ubuntu adb devices 找不到任何东西,安装驱动
			
在Android平台下做开发,adb总是需要使用到的,同时,因为linux没有windows这样操作傻瓜化,有些东西还是需要自行设置的,否则将会连接不上. 关于这些内容,google也有一定的描述,可 ...
 - mao/reduce实现求平均值
			
import java.io.*; import java.util.*; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io. ...
 - python中类的继承
			
python中类的继承 在python中面向对象编程中实现继承,以下面一个实例进行说明. class SchoolMenber(): # __init__类似于c++中的构造函数 # __init__ ...
 - Yii常用技巧总结
			
//YII framework路径 Yii::getFrameworkPath(); //protected/runtime Yii::app()->getRuntimePath(); //pr ...
 - 获取toast值
			
/** * 获取Toast的String值 * @return */ public String getToast(int timeout){ TextView toastTextView = nul ...
 - Winform DataTable 客户端操作数据
			
//创建 DataTable DataTable dt = new DataTable(); dt.Columns.Add("ID"); dt.Columns.Add(" ...
 - ZBar只扫描二维码/条形码
			
You can add these codes for ImageScanner scanner.setConfig(0, Config.ENABLE, 0); //Disable all the S ...
 - hdu 1247 Hat’s Words(字典树)
			
Hat's Words Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
 - [Usaco2006 Nov]Corn Fields牧场的安排 壮压DP
			
看到第一眼就发觉是壮压DP 然后就三进制枚举子集吧. 这题真是壮压入门好题... 对于dp[i][j] 表示第i行,j状态下前i行的分配方案数. 那么dp[i][j]肯定是从i-1行转过来的 那么由于 ...