Wednesday, July 2, 2025

GUESS THE NUMBER

 //creating a guess the number game

import java.util.*;
public class GuesstheNumber {
    public static void main(String[] args) {
      Scanner sc=new Scanner(System.in);
      Random rc=new Random();
      System.out.println("Welcome to my game \n\t how many rounds do you want to play \n\tplease choose a number from 0 to 10");
      //taking inputs and randomly generating no ,also deciding no of rounds player wants to play
        int round=sc.nextInt();
      int input=sc.nextInt();
   
      int computer=rc.nextInt(11);
      int score=0;
      System.out.println("YOU CHOSE "+input);
      System.out.println("COMPUTER CHOSE "+computer);
      //setting rules for game
      for(int i=0;i<round;i++){
      if(input==computer){
        System.out.println("YOU HAVE WON THE GAME");
        score=score+4;
        break;
      }else{
        System.out.println("OH DEAR,YOU HAVE LOST THE GAME");
        score--;
        break;
      }
     
    }
    System.out.println(score);
}
}

No comments:

Post a Comment

list in c#

  using System ; using System . Collections . Generic ; class Program {     static void Main () {         // Write your C# code here  ...