What's problem in this code!

import java.util.Scanner;

public class OanTuTi {

public OanTuTi() {
	// TODO Auto-generated constructor stub
}

public static void main(String[] args) {
	System.out.println("Scissor, Rock, Paper game start!");
	Scanner scan = new Scanner(System.in);
	int user = 0;
	String userNhap = nhapUser(scan);
	switch (userNhap) {
	case "Scissor":
		user = 1;
		return; 
	case "Rock":
		user = 2;
		return; 
	case "Paper":
		user = 3;
		return; 
		
	case "No":
		user = 0;
		System.out.println("");
		return;
	}
	
	int random = (int)(Math.random()*3+1);
		if (user == 1 && random ==1) {
			System.out.println("Computer choose Scissor, Hoa");
		}
		else if (user == 1 && random ==2) {
			System.out.println("Computer choose Rock, Computer win");
		}
		else if (user == 1 && random ==3) {
			System.out.println("Computer choose Paper, User win");
		}
		else if (user == 2 && random ==1) {
			System.out.println("Computer choosen Scissor, User win");
		}
		else if (user == 2 && random ==2) {
			System.out.println("Computer choose Rock, Hoa");
		}
		else if (user == 2 && random ==3) {
			System.out.println("Computer choose Paper, Computer win");
		}
		else if (user == 3 && random ==1) {
			System.out.println("Computer choose Scissor, Computer win");
		}
		else if (user == 3 && random ==2) {
			System.out.println("Computer choose Rock, User win");
		}
		else if (user == 3 && random ==3) {
			System.out.println("Computer choose Paper, Hoa");
		}
	}

public static String nhapUser(Scanner scan) {
	System.out.println("Please choose Scissor, Rock, Paper or type No to finish game");
	String userNhap = scan.nextLine();
	return userNhap;
}

}

The main problem might be that that you are completely leaving the program on any valid input (return vs break).

And BTW: Please further describe your problem next time. What results did you expect, which did you get`? Do you receive error messages at compilation or run time? …

1 Like

Thanks for your comment. I appreciate it.
I will give clearly detail inthe next time.