Skip to main content

Featured

The STEM Revolution: From Classrooms to Code Camps

  In Nepal, the "STEM Revolution" represents a significant departure from memorization and a move toward experiential, hands-on science, technology, engineering, and math education. This approach recognizes that although traditional classrooms are fundamental, they frequently fail to provide students with the critical thinking and problem-solving abilities that the modern world requires.  It is motivated by a shared understanding that in order for Nepal's youth to prosper in the digital era, they must not only comprehend ideas but also learn how to use them creatively to address pressing issues. Making education relevant and enabling students to be creators of technology rather than merely consumers are the goals of this revolution. Dynamic, unofficial learning settings like maker spaces, robotics clubs, and programming camps are at the core of this movement. These programs, which are frequently run by neighborhood tech companies and non-profits, act as dynamic centers...

Rock, Paper, Scissor Game in Java

We can make a simple rock, paper, scissor game in java. Heres, the code:


 import java.util.Scanner;

import javax.lang.model.util.ElementScanner14;

import java.util.Random;

public class App {

    public static void main(String[] args) throws Exception {

        Scanner scan = new Scanner(System.in);

        Random rand = new Random();


        int rand_1 = rand.nextInt(3);


        System.out.println("\nRock, Paper, Scissior Game");

        int trial = 1;

        int player_score = 0;

        int computer_score = 0;


        while (trial<=5) {

            System.out.println("\n0) Rock");

            System.out.print("1) Paper");

            System.out.print("\n2) Scissior");


            System.out.print("\nEnter the choice number: ");

            int choice = scan.nextInt();

            

            // System.out.println(rand_1);


            if (choice == rand_1) {

                System.out.println("Player and Computer Selected Same ");

                // System.out.println("Computer Choice: "+ rand_1);

            } else {


                switch (choice) {

                    case 0:

                        System.out.println("Computer choice: "+ rand_1);

                        if(rand_1<2){

                            if(0<rand_1){

                                System.out.println("Computer wins Match round "+ trial);

                                computer_score = computer_score+1;

                            }

                        }else{

                            System.out.println("Player wins Match round "+ trial);

                            player_score = player_score+1;

                        }

                        break;

                    case 1:

                        System.out.println("Computer choice: "+ rand_1);

                        if(0<rand_1){

                            if(1<rand_1){

                                System.out.println("Computer wins Match round "+ trial);

                                computer_score = computer_score+1;

                            }

                        }else{

                            System.out.println("Player wins Match round "+ trial);

                            player_score = player_score+1;

                        }

                        break;

                    case 2:

                        System.out.println("Computer choice: "+ rand_1);

                        if(rand_1<1){

                            if(rand_1<2){

                                System.out.println("Computer wins Match round "+ trial);

                                computer_score = computer_score+1;

                            }

                        }else{

                            System.out.println("Player wins Match round "+ trial);

                            player_score = player_score+1;

                        }

                        

                        break;

                    default:

                        System.out.println("Wrong input");

                        break;

                }   

            }

            trial = trial+1;

        }

        System.out.println("\nPlayer Score: "+ player_score);

        System.out.println("Computer Score: "+computer_score);

    

        if (player_score>computer_score) {

            int sp = player_score-computer_score;

            System.out.println("\nPlayer won the game by " + sp);

        } else if(computer_score>player_score) {

            int cp = computer_score-player_score;

            System.out.println("\nPlayer lose the game by "+cp);

        }else{

            System.out.println("\nNo one wins the game");

        }

    }


}


Comments

Popular Posts