Multi branch practice stone scissors cloth

The code is as follows:

/*Multi branch practice stone scissors paper randomly generates a number of 0 / 1 / 2 representing stone / scissors / paper respectively, prompting the user to enter 0 / 1 / 2 to judge the win or lose * / import Java util. Scanner; Class demo14 {public static void main (string [] args) {/ / randomly generate int computer = (int) (math. Random() * 3); / / prompt the user to enter scanner SC = new scanner (system. In); system.out.println ("please enter a number of 0 / 1 / 2 to represent stone head / scissors / cloth respectively"); int person = sc.nextint(); switch (computer) {case 0: system.out.println ("stone from computer") ; break; case 1:System. out. Println ("scissors from the computer"); break; case 2:System. out. Println ("cloth produced by computer"); break; } Switch (person) {case 0: system. Out. Println ("computer made stone"); break; case 1: system. Out. Println ("computer made scissors"); break; case 2: system. Out. Println ("computer made cloth"); break;}// Judge if ((computer = = 0 & & person = = 1) | (computer = = 1 & & person = = 2) | (computer = = 2 & & person = = 0)) / / the computer wins the system out. Println ("computer wins"); Else if ((computer = = 0 & & person = = 2) | (computer = = 1 & & person = = 0) | (computer = = 2 & & person = = 1)) / / people win system out. Println ("people win"); Else / / draw system out. Println ("draw");}}

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>