Review java the first day

I haven't touched Java for a long time. I haven't touched it for more than a year since I studied in the second semester of the sophomore year. Forget everything, start from scratch and start again today.

Tonight I wrote a guessing game (not perfect) to review the basics of interfaces, classes, calls, and basic sentences.

import java.util.*;
interface GameOS
{
	public void startgame();
	public void gamebody();
	public void endgame();
}

class game implements GameOS{
	public void startgame() {
		System.out.print("欢迎玩游戏请按  1 取消请按其他数字键 \n");
		int flag;
		Scanner sc = new Scanner(System.in);
		flag = sc.nextInt();
		if(flag == 1)
		{
			gamebody();
		}else {
			endgame();
		}
	}
	public void gamebody() {
		Scanner sc = new Scanner(System.in);
		System.out.print("请您选择: 0 or 1 or 2 \n");
		int man = sc.nextInt();
		int rob;
		rob =(int)(Math.random() * 4);
		System.out.print(rob);
		if(rob > man)
		{
			System.out.print("\n 你输了! \n");
			System.out.print("你还要再来吗 1 yes 其他数字键  no \n");
			int flag = sc.nextInt();
			if(flag == 1)
			{
				gamebody();
			}else {
				endgame();
			}
		}else {
			System.out.print("\n 你赢了! \n");
			System.out.print("你还要再来吗 1 yes 其他数字键  no \n");
			int flag = sc.nextInt();
			if(flag == 1)
			{
				gamebody();
			}else {
				endgame();
			}
		}
	}
	public void endgame() {
		System.out.print("再见!");
	}
}

public class Game1 {

	public static void main(String[] args) {
		game aa = new game();
		aa.startgame();
		// TODO 自动生成的方法存根
	}

}

Lack of integration, you can achieve a single running integration after looking at the array. After all, after exiting, gc. Can't find it again.

Seek slowly tomorrow. There is also a test of amateur radio A question bank has not finished reading qwq.

Guess you like

Origin blog.csdn.net/github_36544258/article/details/100005862