Java Exercise 3: Guess the Number (OOPs Edition)

  Рет қаралды 281,588

CodeWithHarry

CodeWithHarry

Күн бұрын

Java Practice: In this video you will have to solve an exercise on Java Object Oriented Programming. This video is about solving a problem called guess the number where you will have to guess the number computer has generated
I hope you are liking this java complete course for beginners
►This playlist is a part of my Complete Java Course playlist: • Java Tutorials For Beg...
►Source Code + Notes - codewithharry....
►Ultimate Java CheatSheet: codewithharry....
►Checkout my English channel here: / programmingwithharry
►Click here to subscribe - / @codewithharry
Best Hindi Videos For Learning Programming:
►Learn Python In One Video - • Python Tutorial In Hin...
►Python Complete Course In Hindi - • Python Tutorials For A...
►C Language Complete Course In Hindi -
• C Language Tutorials I...
►JavaScript Complete Course In Hindi -
• JavaScript Tutorials I...
►Learn JavaScript in One Video - • JavaScript Tutorial
►Learn PHP In One Video - • Learn Php In One Video...
►Django Complete Course In Hindi -
• Python Django Tutorial...
►Machine Learning Using Python - • Machine Learning Tutor...
►Creating & Hosting A Website (Tech Blog) Using Python - • [Hindi] Web Developmen...
►Advanced Python Tutorials - • Intermediate/Advanced ...
►Object Oriented Programming In Python - • Object Oriented Progra...
►Python Data Science and Big Data Tutorials - • Python Data Science an...
Follow Me On Social Media
►Website (created using Flask) - www.codewithhar...
►Facebook - / codewithharry
►Instagram - / codewithharry
►Personal Facebook A/c - / geekyharis
Twitter - / haris_is_here

Пікірлер: 1 100
@eshlovesyou6079
@eshlovesyou6079 2 жыл бұрын
I have tried learning java so many times but i failed every single time books, courses, tutorials; but your videos have helped me understand all the concepts from calling objects, creating classes methods and everything. Thank you so much for making this wonderful course free for students like us to access!
@prasadg.5736
@prasadg.5736 Жыл бұрын
Learn DSA then u will understand everything 👍
@samadhantilkar1720
@samadhantilkar1720 7 ай бұрын
😂😂😂​@@prasadg.5736
@exploreworld3631
@exploreworld3631 14 күн бұрын
How??​@@prasadg.5736
@saurabhjoshi8001
@saurabhjoshi8001 3 жыл бұрын
Your teaching is very well...You are the best teacher in the world...Love you harry sir..You deserve billion of subscribers..
@rpyoutuber9041
@rpyoutuber9041 3 жыл бұрын
This is the truth
@shaiksunny669
@shaiksunny669 2 жыл бұрын
@@rpyoutuber9041 by 😁22
@shaiksunny669
@shaiksunny669 2 жыл бұрын
@@rpyoutuber9041 😏😏😏
@shaiksunny669
@shaiksunny669 2 жыл бұрын
@@rpyoutuber9041 😏😏😏😏😏😏
@shaiksunny669
@shaiksunny669 2 жыл бұрын
@@rpyoutuber9041 😏😏😏😏😏😏
@rohitsorot5136
@rohitsorot5136 3 жыл бұрын
DATA STRUCTURE WITH JAVA BY HARRY BHAI eagerly waiting 2020 passout want to learn this for getting job
@rohitsorot5136
@rohitsorot5136 3 жыл бұрын
@IT'S YK no abhi tak nahi...still learninig dsa
@abhijeetdhumal8650
@abhijeetdhumal8650 2 жыл бұрын
Best of luck give your best and try to join any were. Dont see how many salary they give
@techeduidea2598
@techeduidea2598 2 жыл бұрын
Harry bhaiya please bring "DATA STRUCTURE WITH JAVA "
@skestatusvideo7785
@skestatusvideo7785 10 ай бұрын
Sir your teaching style is awesome and i will understand all lectures but still i m not able to solve the question by myself 🥲🥲🥹🥹 please sir tell mewhat to do
@rupakkumarbag33
@rupakkumarbag33 3 жыл бұрын
You r really doing a good think by crating such Playlist of java course. Thank u so much.
@photoshopproduction6733
@photoshopproduction6733 Жыл бұрын
I have watching your video recently and learned lot about java with help of yourself sir... Thank you so much for making the videos and made me learned java programming with easier concepts and fun way of telling the concepts😇♥️
@udhavsharma1882
@udhavsharma1882 2 жыл бұрын
Solution using do while loop; import java.util.Random; import java.util.Scanner; class game{ public int a,b,c=0; public int game() { Random random= new Random(); a= random.nextInt(0,100); return a; } public void getuserinput() { do { Scanner sc= new Scanner(System.in); System.out.println("Guess the nubmer: "); b = sc.nextInt(); if (a>b) { System.out.println("Think for a biger number"); } else if (a
@shambu6181
@shambu6181 Жыл бұрын
random.nextInt(0,101); // to get values from 0 to 100.
@priyankaprusty2274
@priyankaprusty2274 5 ай бұрын
Constructor ka kuch return type nhi hota ...
@priyankaprusty2274
@priyankaprusty2274 5 ай бұрын
Public int game () // int is a return type
@shreyashkulkarni2379
@shreyashkulkarni2379 29 күн бұрын
Bro there is not need to call a constructor call explicitly I think you wanted to Make a method to get it OK , So it should be Maine Class game{ Int a,b,c; Public game(){ Random random=new Random(); a=random.nextint(); b=0; c=0; }
@shreyashkulkarni2379
@shreyashkulkarni2379 29 күн бұрын
If you could make a,b,c a private attribute
@meetthakkar3135
@meetthakkar3135 2 жыл бұрын
Learning Java is easy with this course --> Thank you 😊
@hetvifuria7174
@hetvifuria7174 2 жыл бұрын
You are the best teacher in the world!!!!!
@iamxgaming8803
@iamxgaming8803 3 жыл бұрын
Hi bro, I am currently learning java from your java tutorial course on youtube and I just want to tell you that , I am currently on video(43. Guess the number), right now I am so boosted because i just made that game(guessing the number) at my first attempt without any errors or exception 😅
@iamxgaming8803
@iamxgaming8803 3 жыл бұрын
Nd sorry I'm so lazy that I wrote this to dm you on insta nd now posting it here without making or correcting anything,
@dangergamimg1933
@dangergamimg1933 2 жыл бұрын
So how much you learned in 9 months
@pooja581
@pooja581 3 жыл бұрын
Your lectures are amazing Harry Bhai
@lalitshah7867
@lalitshah7867 3 жыл бұрын
I can call all word this is a man who is a best teacher all programing sir please everyday aise video sur
@abrar_hamim
@abrar_hamim Жыл бұрын
I came to this course a bit late but can say with confident , I am learning, truly learning. Appreciate all your hardworks harry vaiya ❤
@NDOSPARTAN11
@NDOSPARTAN11 2 жыл бұрын
here my code goes ); package OOPS; import java.util.Scanner; import java.util.Random; class Game{ public int ComputerInput , UserGuess , no_of_guess =0; //constructor for Genrating random number ------------- public Game(){ Random random = new Random(); ComputerInput = random.nextInt(10); } // method to take guess from user ------------------------- public void UserInput(int num){ UserGuess = num; } // method to check weather users guess is right or wrong ---------------- /* this while method will check weather the number chosen by user is equal to number generated by computer is right or wrong like wise ti will update the value of no_of_guess every time and return true or false as result */ public boolean IsCorrectNumber(){ if(UserGuess > ComputerInput){ System.out.println("You have chosen Bigger No"); no_of_guess = no_of_guess + 1; return false; } else if(UserGuess < ComputerInput){ System.out.println("You have Chosen Smaller number"); no_of_guess = no_of_guess + 1; return false; } else { System.out.println("Your Guess is Correct"); no_of_guess = no_of_guess + 1; System.out.println("Number of Guess required : "+no_of_guess); return true; } } } public class GuessTheNumber { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("WELCOME TO GUESS THE NUMBER GAME ! "); /* by creating object player we have called Game constructor and ------------- the Game() constructor contain definition to generate a random number so random number will be generated as we know when object is created Constructor is called*/ Game player = new Game(); /// this will take input from user as guess --------------------- System.out.println("Guess the Number from 0 to 10 : "); player.UserInput(sc.nextInt()); /* this loop will run util the condition become true ------------------- if IsCorrectGuess function return false then it will call function UserInput() until result gets true and according to condition update the value of no_of_guess */ while(!player.IsCorrectNumber()){ System.out.println("Guess the Number Again"); player.UserInput(sc.nextInt()); } } }
@JAYSHREEKHANKE
@JAYSHREEKHANKE 6 ай бұрын
Challenge Accepted! you are classes very helpful to me. And my all doubt clear to attend your classes regularly as very well improvement my idea. So, thank you so much sir you conducting free Java classes for many students it is very helpful us.
@_devansh_rana
@_devansh_rana 2 жыл бұрын
thank you harry bhai for your support and guidance...thanks for being a mentor for us...!
@mohammadimran6764
@mohammadimran6764 3 жыл бұрын
bhai...youtube mein search kari lekin aapke jaise bolne person nahimila bhai....simple learn,great learning wale ne tho kya sikha rahe hai kuch understanding he nahi hai...bus woh log lips se bole jarahe hai..bus jyada baatein bhi aapke liye kaafi nahi hai....thanks a lot for teaching us...dil se
@omkark7118
@omkark7118 Жыл бұрын
// used constructor to generate random number // used setNum() to set number // used isCorrect() method to check // used Counter() to count number of guesses import java.util.Scanner; class Game{ private int counter = 0; private int myNumber; private int compNumber; public Game(){ compNumber = (int) (Math.random()*100); } public void setNumber(int n){ myNumber = n; } public int isCorrect(){ if(myNumber == compNumber){ return 0; } else if(myNumber > compNumber){ return -1; } else{ return 1; } } public void setCounter(){ counter++; } public void getCounter(){ System.out.println("The number of guesses were "+ counter); } } public class Main{ public static void main(String[] args) { Game obj = new Game(); Scanner sc = new Scanner(System.in); while(true){ System.out.println("Enter a number between 1 to 100 (1-100): "); int n = sc.nextInt(); obj.setNumber(n); if(obj.isCorrect() == 0){ obj.setCounter(); System.out.println("Congratulations!! You have guessed the correct number"); obj.getCounter(); break; } else if(obj.isCorrect() == -1){ obj.setCounter(); System.out.println("Enter smaller number!!"); } else if(obj.isCorrect() == 1){ obj.setCounter(); System.out.println("Enter larger number!!"); } } } }
@bgmigaming4593
@bgmigaming4593 Жыл бұрын
please tell me how to take inputs again and again java.util.Scanner; import java.util.Random; class Game{ int a;// user input Number int b;// computer guess Number int guess=0; public Game(){ Scanner s=new Scanner(System.in); Random r=new Random(); b=r.nextInt(10)-1; } public void takeUserInput(){ Scanner s=new Scanner(System.in); System.out.println("Please enter any numbr between 1 to 10 --> "); a=s.nextInt(); } public void isCorrectNumber(){ if(a==b){ System.out.println("Numbers Match"); } else if(a>=b){ System.out.println("Entered number is Greater Try again"); guess++; } else{ System.out.println("Enter number is Smaller Try again"); guess++; } } public int getGuess(){ return guess; } } public class Main { public static void main(String[] args) { System.out.println("Lets Play the Game"); Game r=new Game(); r.takeUserInput(); r.isCorrectNumber(); System.out.println("guess = "+r.getGuess()); } }
@omkark7118
@omkark7118 Жыл бұрын
@@bgmigaming4593 you need to put your takeUserInput and isCorrectNumber is a while loop and when the user input matches give break statement.
@bgmigaming4593
@bgmigaming4593 Жыл бұрын
@@omkark7118 pls edit this in my code....🙏
@visu_saini19632
@visu_saini19632 Жыл бұрын
Yes java is very easy whin i watch you java playlist
@30vaibhavdhaygondexdr.v.sa22
@30vaibhavdhaygondexdr.v.sa22 3 жыл бұрын
Actually I am not going to watch this series because I get so excited for next videos, so when the count of the video crosses 30 then I will watch the whole series. I can't believe that the knowledge which is worth lakhs of rupees, he is distributing it for free!!! Thank you Harry SIr
@ameybhandari6865
@ameybhandari6865 Жыл бұрын
Thanks harry for this video!!
@kartik_265
@kartik_265 3 жыл бұрын
Challenge completed : // range reduced to 0-10 import java.util.Scanner; import java.util.Random; class game{ Scanner sc=new Scanner(System.in); int n; int g; int p; game(int q){ n=q; g=0; } void getter(){ System.out.println("Enter a number"); p=sc.nextInt(); g++; process(p); } void process(int s){ if(s==n) { System.out.println("You won"); System.out.println("No. of attempts :"+g); } else if(s>n) { System.out.println("Entered number is greater"); getter(); } else { System.out.println("Entered number is smaller"); getter(); } } } public class MethodArea { //Scaneer class object must be declared inside the main function public static void main(String[] args) { //Scanner sc=new Scanner(System.in); Random r=new Random(); int a; a=r.nextInt(11); game g=new game(a); g.getter(); } }
@abhinavnair4577
@abhinavnair4577 2 жыл бұрын
Thanks kartik
@GULLAPUDILIKITHBCE
@GULLAPUDILIKITHBCE 2 жыл бұрын
but it wont stop even chances are completed?
@chaitanyashahane7085
@chaitanyashahane7085 3 жыл бұрын
Thank you you are a great teacher !!!! import java.util.Random; import java.util.Scanner; class Game4 { public int userinput,compinput; Random random=new Random(); Scanner sc=new Scanner(System.in); public int Game4() { compinput=random.nextInt(100); return compinput; } public int takeuserinput() { userinput=sc.nextInt(); return userinput; } public int iscorrectInput() { if(userinput==compinput) { return 1; } else return 0; } } public class game_3 { public static void main(String[] args) { int y,k=0,m,n; Game4 ob=new Game4(); m=ob.Game4(); System.out.println("Welcome to the game "); System.out.println("In this game the computer will generate a random integer from 0-100 you have to guess it in least number off guesses"); System.out.println("The computer will guide you whether your guess is greater or smaller than comp input"); while(ob.iscorrectInput()==0) { k++; System.out.println("Enter your guess!!"); n=ob.takeuserinput(); y=ob.iscorrectInput(); if(y==1) { System.out.print("Correct choice"); break; } if(n>m) System.out.println("Your guess is Greater than computer input"); if(n
@jadugar6985
@jadugar6985 2 жыл бұрын
Constructor mei return type nahi hota bhai
@atirrasheedhashmi
@atirrasheedhashmi 2 жыл бұрын
Impressive COde, maza aagya 👍
@himankjeshwar8636
@himankjeshwar8636 2 жыл бұрын
Dear Chaitanya Shahane , you have certain mistakes in your code , I have corrected your code you can have a look in this :- // CHANGES MADE :- // Removed the return type from constructor. // Changed the names of some variables to make them meaningful. // Added getters and setters for noOfGuesses. (as per the question) import java.util.Scanner; import java.util.Random; class Game4 { public int userinput,compinput,noOfGuesses=0; Random random=new Random(); Scanner sc=new Scanner(System.in); public Game4() // Constructors cannot have a return type (not even void) { compinput=random.nextInt(101); // goes from 0 to 100 } public void takeuserinput() { userinput=sc.nextInt(); } public int iscorrectInput() { if(userinput==compinput) { return 1; } else return 0; } public void setnoOfGuesses(int guess){ noOfGuesses = guess; } public int getnoOfGuesses(){ return noOfGuesses; } } public class game_3 { public static void main(String[] args) { // TIP - Variable names should be meaningful. // So , I have changed the names of the some variables :- // m is changed to compNo. // n is changed to userNo. // removed variable k . (not needed as we are using getters and setters for noOfGuesses) // y is changed to checkInput. int checkInput,compNo,userNo; Game4 ob=new Game4(); checkInput = ob.iscorrectInput(); compNo=ob.compinput; // returns compinput to variable compNo System.out.println("Welcome to the game "); System.out.println("In this game the computer will generate a random integer from 0-100 you have to guess it in least number off guesses"); System.out.println("The computer will guide you whether your guess is greater or smaller than comp input"); while(checkInput==0) { ob.setnoOfGuesses(++ob.noOfGuesses); /* The above statement increments ob.noOfGuesses by 1 in each iteration use pre-increment operator (++ before the variable) as it increments the value first and then sends the copy of this new value to the function.*/ System.out.println("Enter your guess!!"); ob.takeuserinput(); // takes input userNo = ob.userinput; // returns the userInput to variable userNo checkInput=ob.iscorrectInput(); // checks input if(checkInput==1) { System.out.println("Correct choice"); break; } if(userNo>compNo) System.out.println("Your guess is Greater than computer input"); if(userNo
@shuvamsarkar9086
@shuvamsarkar9086 2 жыл бұрын
@@himankjeshwar8636 good job.✌️👍
@hrithikrudra4292
@hrithikrudra4292 3 жыл бұрын
When will be Android development in one video be uploaded?
@jsquare_ninja1058
@jsquare_ninja1058 3 жыл бұрын
it has already been uploaded on his channel.
@GauravKumar-qt1yx
@GauravKumar-qt1yx 3 жыл бұрын
Harry bhai no doubt you are the best teacher Please make a video on java security (why java is so secure)
@anugupta6834
@anugupta6834 Жыл бұрын
bcz java does not allow pointer in her garden
@GauravKumar-qt1yx
@GauravKumar-qt1yx Жыл бұрын
@@anugupta6834 no I think because of JVM
@trueknowledge2065
@trueknowledge2065 3 жыл бұрын
SOLUTION import random number = 200 n = random.randint(1, number) print('Welcome to guess the number game!') print('Guess the number from 1 to %d' % number) guess = None while guess != n: guess = int(input('Your try: ')) if guess > n: print('Too high') if guess < n: print('Too low') print('Congratulations, you won!') SOLUTION IS IN PYTHON BECAUSE I AM PAPA PYTHON Harry sir please upload Tensorflow Tutorials please
@Unknown-Stranger
@Unknown-Stranger 3 жыл бұрын
tutotial java ka exercise java m mangi h tu python lga rha h
@trueknowledge2065
@trueknowledge2065 3 жыл бұрын
@@Unknown-Stranger I AM PAPA PYTHON BRO!!!!
@Sunday100
@Sunday100 3 жыл бұрын
Wow
@shivamsrivastava5827
@shivamsrivastava5827 3 жыл бұрын
@@trueknowledge2065 bro tu brake lele programming se Java or Python me confuse ho raha hai. 😁🤣 Tutorial Java ka hai or exercise bhi java ki hi hai solution bhi to java ka hi hona chahiye na. 🤣😁😂
@trueknowledge2065
@trueknowledge2065 3 жыл бұрын
@@shivamsrivastava5827 I AM PAPA PYTHON BRO!!!!
@-uq1sl
@-uq1sl Жыл бұрын
Thanku So much sir to helping me in java with proper note
@artifice_abhi
@artifice_abhi 2 жыл бұрын
// used constructor to generate random number // used setNum() to set number // used isCorrect() method to check // used Counter() to count number of guesses package com.abhinav; import java.util.Scanner; class Game{ int userNumber; int compNumber; int counter = 0; public Game(){ compNumber = (int)(Math.random()*100); System.out.println(compNumber); } public void setNum(int n){ userNumber = n; } public int isCorrect(){ if(userNumber > compNumber) return -1; else if(userNumber < compNumber) return 1; else return 0; } public void Counter(){ counter++; } } public class CH_28_Guess_the_Number_OOPS { public static void main(String[] args) { Game obj = new Game(); Scanner sc = new Scanner(System.in); int n = 0; while(true){ System.out.println("Enter a number between 1-100: "); n = sc.nextInt(); obj.setNum(n); if(obj.isCorrect() == 0){ obj.Counter(); System.out.println("Congratulations, You've guessed the number."); System.out.println("Number of counts: " + (obj.counter)); break; } else if(obj.isCorrect() == 1){ obj.Counter(); System.out.println("Higher number please!"); } else if(obj.isCorrect() == -1){ obj.Counter(); System.out.println("Lower number please!"); } } } }
@iread8616
@iread8616 2 жыл бұрын
good answer
@pie2790
@pie2790 2 жыл бұрын
I am understanding all the concepts everything but I am not able to solve problems by myself without seeing the comments for the solution???
@iread8616
@iread8616 2 жыл бұрын
@@pie2790 its fine bro, but make sure you shiuld try to attempt it 2-3 times before jumping into the solution, think with different methods, its still okay if you take much more time and still can't solve it, it will take time but gradually you will start making progress, Best of Luck Buddy
@sudarshanbhosale
@sudarshanbhosale 2 жыл бұрын
@@pie2790 same here
@akshaykakade3782
@akshaykakade3782 2 жыл бұрын
@@pie2790 sabke liye same he ,,dont worry
@toxicgamer4095
@toxicgamer4095 3 жыл бұрын
package Course_2; import java.util.Random; import java.util.Scanner; class Guess { public Guess(int x,int y,int i) { if(y==x) { System.out.println("Congratulations you won this game in"+" "+i+" "+"chance"); System.exit(i); } else if(y>x) { System.out.println("The computer number is greater"); } else { System.out.println("The computer number is smaller"); } } } public class Challege_Accepted { public static void main(String[] args) { Random r=new Random(); int r1=r.nextInt(100); Guess su[]=new Guess[6]; Scanner sc=new Scanner(System.in); System.out.println("You have only five guesses"); for(int i=1;i
@techhigh1833
@techhigh1833 3 жыл бұрын
Nice program 👍
@om2455
@om2455 3 жыл бұрын
Nice program
@toxicgamer4095
@toxicgamer4095 3 жыл бұрын
Thanks
@satvikmittal4487
@satvikmittal4487 3 жыл бұрын
bro let the user enter the number until he gets it correct.Dont bound the tries to 5
@toxicgamer4095
@toxicgamer4095 3 жыл бұрын
@@satvikmittal4487 bro this condition given by harry bhai so if you want then you can change this code as per your need ok.
@sanskritigupta865
@sanskritigupta865 2 жыл бұрын
Solved it... /* Create a class Game, which allows a user to play "Guess the Number" game once. Game should have the following methods 1. Constructor to generate the randome number 2. takeUserInput() to take user input of number 3. isCorrectNumber() to detect whether the numebr enetered by the user is true 4. getter and setter for noOfGuesses Use properties such as noOfGuesses(int) , etc to get this task done ! */ import java.lang.Math; import java.util.Scanner; class Game { int random_number, user_input; static int noOfGuesses=0; Game() { random_number = (int)(Math.random()*(100-0+1) + 0); } public void takeUserInput(int n) { user_input = n; } public int isCorrectNumber() { if(user_input == random_number) { return noOfGuesses++; } else if(user_input > random_number) { noOfGuesses++; System.out.print(" The enetered number is greater than the random number generated. "); return 1; } else { noOfGuesses++; System.out.print(" The entered number is less than the random number generated. "); return 1; } } } public class cwh_exercise3 { public static void main(String[] args) { Scanner var = new Scanner(System.in); int u; System.out.print(" Enter a number: "); u=var.nextInt(); Game obj = new Game(); obj.takeUserInput(u); int i = obj.isCorrectNumber(); while(i == 1) { u=var.nextInt(); obj.takeUserInput(u); i = obj.isCorrectNumber(); } System.out.print(" No of Guesses: " + (i+1)); } } I know that I am late, but I did it...
@kartiksambhu7410
@kartiksambhu7410 Жыл бұрын
WTF it's too big
@Prathamesh107
@Prathamesh107 Жыл бұрын
there's a wrong test case where if you get the answer right on second try it still asks you to enter new number
@himankjeshwar8636
@himankjeshwar8636 2 жыл бұрын
Code for Guess The Number Game (AUTHOR - HIMANK JESHWAR) :- import java.util.Scanner; import java.util.Random; class Game{ int randInt,userInt,noOfGuesses=0; public Game(){ Random rand = new Random(); randInt = rand.nextInt(101); } public void takeUserInput(){ Scanner gameInput = new Scanner (System.in); System.out.print("Guess any number (0 to 100) = "); userInt = gameInput.nextInt(); } public void isCorrectNumber(){ if (userInt>randInt){ System.out.println("\tTOO HIGH !"); } else if (userInt
@SandeepThakur-wf5vm
@SandeepThakur-wf5vm 6 ай бұрын
7:11
@vivelafootball4835
@vivelafootball4835 2 жыл бұрын
/*Create a class Game, which allows a user to play "Guess the Number" game once. Game should have the following methods: Constructor to generate the random number takeUserInput() to take a user input of number isCorrectNumber() to detect whether the number entered by the user is true getter and setter for noOfGuesses*/ import java.util.*; class OOP { static int TakeUserInput() { Scanner sc=new Scanner(System.in); int z=sc.nextInt(); return z; } static void IsCorrect() { Random rnd=new Random(); int y=rnd.nextInt(10); int c=0; while(true) { int x=TakeUserInput(); if((x ^ y) == 0) { System.out.println("You have guessed the number correct"); c=c+1; break; } else { System.out.println("You have guessed the number incorrect. Try again."); c=c+1; } } System.out.println("You Won and your score is : "+c); } } public class GuessTheNumberOnce { public static void main(String[] args) { //Scanner sc=new Scanner(System.in); OOP ob=new OOP(); ob.IsCorrect(); } }
@himankjeshwar8636
@himankjeshwar8636 2 жыл бұрын
don't name the class OOP , name it as Game , because the name of the class is given the question and you need to abide by the question.
@HemantKumar-wy1hj
@HemantKumar-wy1hj 3 жыл бұрын
Harry Bhai meri MCA complete ho gyi hai aage kya kru
@AdarshSingh-cb5yf
@AdarshSingh-cb5yf 3 жыл бұрын
Bhai mca kha se kiye ho ....??(kis college se)
@surajyadav-tb3yt
@surajyadav-tb3yt 3 жыл бұрын
Sir please update quickly I want to learn through your vedio
@promiladan8904
@promiladan8904 3 жыл бұрын
👋Hii, bro pls make a video on "complete roadmap for software engineer" pls pls pls pls pls pls 🙏🙏🙏🙏🙏🙏🙏🙏...... I hope your are reading my comment so psl make the video🙏🙏☺️
@sjsaif3460
@sjsaif3460 3 жыл бұрын
Yeah bro i need it
@darshanthakor182
@darshanthakor182 3 жыл бұрын
Sir battleship game ke bare Mai bataao using array in java
@allencordeiro5435
@allencordeiro5435 2 жыл бұрын
I know I am late, but Thank You harry, I hated Java from the core, but for work I had to learn it and now I am in Love with OOPS and Java, its fun to do this problem solving. import java.util.Scanner; import java.util.Random; class Game{ public int number; public int inputNumber; public int noOfGuesses = 0; Scanner sc = new Scanner(System.in); public int getNumberOfGuesses() { return noOfGuesses; } public void setNumberOfGuesses(){ noOfGuesses++; } //Constructor to generate random number Game(){ Random random = new Random(); number = random.nextInt(101); System.out.println("*69420"+number+"69420*"); } //method to take user input public void takeUserInput(){ System.out.println("Enter a number between 0 - 100"); inputNumber = sc.nextInt(); setNumberOfGuesses(); if (inputNumber100){ System.out.println("Your Choice: "+inputNumber+"!!!! Please choose number between 0 to 100 only"); noOfGuesses = 0; takeUserInput(); } else{ isNumberCorrect(); } } //method to check if number is correct public void isNumberCorrect(){ if (inputNumber == number){ System.out.println("Correct Choice"); System.out.println("YOU WIN, "+inputNumber+" is the right number"); System.out.println(); System.out.println("You took "+getNumberOfGuesses()+" in total"); System.out.println("- - - - - - - - - - - - - - - - - "); } else if(inputNumber>number) { System.out.println("Try a lesser number"); takeUserInput(); } else{ System.out.println("Try a higher number"); takeUserInput(); } } } public class Main { public static void main(String[] args) { System.out.println("|||||||||||||||||||||||||||||||"); System.out.println(" Lets Play The Guess Game"); System.out.println("|||||||||||||||||||||||||||||||"); System.out.println(); Game allen = new Game(); allen.takeUserInput(); } }
@HemantKumar-wy1hj
@HemantKumar-wy1hj 3 жыл бұрын
Challenge accepted 👍😊
@RehanAliArman-mt8pr
@RehanAliArman-mt8pr 5 ай бұрын
it is very easy to understand and learn
@abhijeetdhumal8650
@abhijeetdhumal8650 2 жыл бұрын
// Creating a Game class //I use Oop and Procedure oriented approach import java .util.Scanner; import java.util.Random; class Game{ Scanner scan=new Scanner(System.in); int rand; int t=1; Game() {//Creating a constructor of game class Random random=new Random(); rand=random.nextInt(100);//Taking random inpute from Computer // System.out.println(rand); int gause=scan.nextInt();//taking inpute from user do {//I use do while() loop for taking repeate inpute from user if(rand==gause) { System.out.println("You gause the Number correctly"); }else if(gause>(rand + 10)){ System.out.println("Your number is so big"); }else if (gause > rand) { System.out.println("Your number is big"); }else if(gauserand) { System.out.println("Your number is small"); } int x=scan.nextInt(); gause=x; t++; } while(rand!=gause); System.out.println("You gauss successfully"); System.out.println("You taken gauss time:- " +t); } } public class Chap_prac_set {//Here you write your own class name. public static void main(String[] args) { System.out.println("Guess the Number game"); Scanner sc=new Scanner(System.in); Game g1=new Game();//creating object of Game class } } //if any advice for me give in comment box
@ritushriwas1829
@ritushriwas1829 2 жыл бұрын
Run nhi ho Raha aap ka program
@mohammedasim6237
@mohammedasim6237 2 жыл бұрын
// Create a class game, Which allows a user to play "Guess the Number" game // once. Game should have the following methods. // 1. Constructor to generate the random number, // 2. takeUserInput() to take a user input of number, // 3. isCorrectNumber to detect whether the number entered by the user is true, // 4. getter and setter for number of guesses, // use properties such as noOfGuesses, etc to get this task done! import java.util.Scanner; import java.util.Random; public class Java_exercise_3_guess_the_number { public static void main(String[] args) { Game myGame=new Game(); boolean playGame=true; int userNumber; while(playGame==true) { userNumber=myGame.takeUserInput(); boolean myBool=myGame.isCorrectNumber(userNumber); if(myBool==true) { System.out.print("Guessed in "); myGame.getNumberOfGuesses(); System.out.print(" Guesses"); System.out.println(""); playGame=false; break; } else { playGame=true; } } } } class Game { private int computerNumber; private int numberOfGuesses=0; Scanner sc=new Scanner(System.in); Random rn=new Random(); public Game() { computerNumber=rn.nextInt(101); } public int takeUserInput() { System.out.println("Guess the number (1-100) : "); int userNumber=sc.nextInt(); return userNumber; } public boolean isCorrectNumber(int myNum) { int flag=0; if(myNum=0) { setNumberOfGuesses(); if(myNum==computerNumber) { System.out.println("You guessed it right. The number is "+myNum); flag=1; sc.close(); } else if(myNumcomputerNumber) { System.out.println("Your number is greater than the actual number"); } } else { System.out.println("Please enter in range 0-100"); } if(flag==1) { return true; } else { return false; } } public void setNumberOfGuesses() { numberOfGuesses++; } public void getNumberOfGuesses() { System.out.print(numberOfGuesses); } }
@gulraizalikhan8012
@gulraizalikhan8012 Жыл бұрын
Nice bro❤❤
@iamyourdaddy7077
@iamyourdaddy7077 Жыл бұрын
super prescise
@akshatsharma6644
@akshatsharma6644 3 жыл бұрын
Thanks sir for this course
@aasheesh6001
@aasheesh6001 Жыл бұрын
I think this code is simple to understand. // Game should have the following methods: // Constructor to generate the random number // takeUserInput() to take a user input of number // isCorrectNumber() to detect whether the number entered by the user is true // getter and setter for noOfGuesses import java.util.Scanner; import java.util.Random; class guess{ int user; int comp; Scanner sc = new Scanner(System.in); Random ran = new Random(); //int Comp = ran.nextInt(10); public int random(){ int comp = ran.nextInt(10)+1; return comp; } public int input(){ System.out.println("Enter your guess number."); int user = sc.nextInt(); return user; } public void result(){ int c=1; int idiot = random(); while(true) { //int idiot = random(); int again = input(); //System.out.println(idiot); //int comp = ran.nextInt(10)+1; //System.out.println(comp); if(idiot == again){ System.out.println("Damn, correct guess!!!" + " You take " +c + " chances"); break; } if(comp>=again){ System.out.println("Little bit higher. "+" You try "+c+" Times."); } else{ System.out.println("Little bit lower. "+ " You try "+c+" Times."); c+=1; } } } } public class Main { public static void main(String[] args){ guess g1 = new guess(); // g1.random(); // g1.input(); g1.result(); } }
@__blank__4193
@__blank__4193 Жыл бұрын
import java.util.Scanner; class game{ private int rand,user,counter=0; public void generator(){ rand=(int)(Math.random()*100); } public void setter() { Scanner sc = new Scanner(System.in); System.out.println("Guess a number (0-100): "); user=sc.nextInt(); } public int backend() { do{ setter(); if(userrand) { counter++; System.out.println("Try smaller number than "+user); } else{ counter++; System.out.println("You guessed correct :"+rand); } }while(user!=rand); return counter; } } public class guess{ public static void main(String[] args) { game user = new game(); user.generator(); System.out.println("No. of tries : "+user.backend()); } }
@sudharshantheproductivityg8908
@sudharshantheproductivityg8908 Жыл бұрын
Thank you! Liked
@subhankarkanrar9494
@subhankarkanrar9494 8 ай бұрын
Meri programming journey apse hi start hua hai. To guruji apko kaise vul 😅 sakte hai
@implementation8489
@implementation8489 3 жыл бұрын
Challange completed --> // Object Oriented Programming practice >>> import java.util.Scanner; import java.util.Random; import java.lang.*; class Game { int RandomNumber; int UserNumber; int noOfGuesses = 0; // Constructor for generating random value... public Game() { Random object = new Random(); int RandNum = object.nextInt(100); this.RandomNumber = RandNum; System.out.println("Random number is generated inside the memory !!!"); } public String TakeUserInput() { Scanner user = new Scanner(System.in); System.out.print("Guess the number: "); int UserNum = user.nextInt(); this.UserNumber = UserNum; System.out.println("Reading.. "+UserNumber); user.close(); // Closing the object by the .close() method.. return "Process Terminated !!!"; } public void IsCorrectNumber() { boolean []ConditionArray = {true,false}; noOfGuesses +=1; // Updating the value while calling this function inside the loop.. // Condition for execution of the program... if (this.UserNumber == this.RandomNumber) { System.out.println("Congratulations !!! Your guess got correct !!!"); System.out.println("Is Number Correct "+ConditionArray[0]); // Input >>> Scanner User = new Scanner(System.in); System.out.print("Do you want to watch your number of guesses [1-Yes],[2-No] >>> "); int UserChoice = User.nextInt(); // Conditions >>> if (UserChoice == 1) { System.out.println("Number of guesses >>> "+noOfGuesses); } else if (UserChoice == 2) { System.out.println("Terminating the game...."); } else { System.out.println("Invalid input provided by the user..."); } System.out.println("----------------------------------------------"); System.exit(0); // Succesfully terminating the function... } else if (this.UserNumber < this.RandomNumber) { System.out.println("Guessed number is smaller than Random Number...."); System.out.println("Is Number Correct "+ConditionArray[1]); System.out.println("----------------------------------------------"); } else if (this.UserNumber > this.RandomNumber) { System.out.println("Guessed number is greater than Random Number...."); System.out.println("Is Number Correct "+ConditionArray[1]); System.out.println("----------------------------------------------"); } } // This is the main method.... public String Main() { // Importatnt methods int counter = 0; while (counter
@shalinmistrybca6636
@shalinmistrybca6636 2 жыл бұрын
how long did it take for you to think logic of program and implement it
@PwVp
@PwVp 5 ай бұрын
import java.util.Scanner; import java.util.Random; public class JavaEx3GuessTheNumGame { public static void main(String[] args) { Game myGame = new Game(); myGame.takeUserInput(); myGame.isCorrectNumber(); } } class Game{ int noOfGuesses; int random; int ip; public Game(){ Random rn=new Random(); random= rn.nextInt(100)+1; } public void takeUserInput(){ Scanner sc=new Scanner(System.in); System.out.println("Take a guess between 0 to 100:"); ip= sc.nextInt(); } public void isCorrectNumber (){ if (ip==random){ System.out.println("Your guess is right."); noOfGuesses++; System.out.printf("You guessed the number in %d chances.",noOfGuesses); } else if (ip>random) { System.out.println("Your guess is greater than the number."); noOfGuesses++; takeUserInput(); isCorrectNumber(); } else if (ip
@harshitrathi3077
@harshitrathi3077 3 жыл бұрын
Thankyou Bhaiya. Please Complete This Java Course Asap
@vishalkumawat9146
@vishalkumawat9146 3 жыл бұрын
Sir dsa ke notes dal do 🙏🙏🙏
@GauravSharma-tj1ki
@GauravSharma-tj1ki Жыл бұрын
solution of exercise 3 package com.company; import java.util.Scanner; class Game{ private int numberOfGuesses=0; private static int status=0; private final int r; private int input; public Game(int ran)//constructor { r=ran; } public void takeUserInput(int num){ input=num; if (rinput){ System.out.println("please enter a larger value than this ."); numberOfGuesses +=1; } else{ numberOfGuesses +=1; } } public void isCorrectNumber() { System.out.println("the number of sequence in which random number is equal to my number is "+status); } public void check(){ status++; } public int getNumberOfGuesses() { return numberOfGuesses; } } public class CWH_41_Excercise_3 { public static void main(String[] args) { Scanner sc= new Scanner(System.in); int random= (int)(Math.random()*100); Game guessTheNumber=new Game(random);//guessTheNumber naam ka ek object banaye hain . System.out.println(random); System.out.println("enter the number between 1 to 100: "); int x=0; while(x>=0) { x =sc.nextInt(); guessTheNumber.check(); if(x==random){ guessTheNumber.isCorrectNumber(); break; } guessTheNumber.takeUserInput(x); } } }
@mohitdahal2257
@mohitdahal2257 3 жыл бұрын
The truth is: Harry is the best teacher
@icjhonny9390
@icjhonny9390 3 жыл бұрын
yes bro
@jayalaxmise8886
@jayalaxmise8886 3 жыл бұрын
Thank u harry sir for this video
@riteshregmi5594
@riteshregmi5594 3 жыл бұрын
Challenge Accepted
@DesiBozs007
@DesiBozs007 Жыл бұрын
Haa bhai help mill rha hai bahut Thank you so kuch😍😍😍👍👍👍👍❤❤❤❤❤
@myinspiration8847
@myinspiration8847 Жыл бұрын
I am too late to enter my code but I hope it will correct package com.company; import java.util.Random; import java.util.Scanner; public class guess_the_no_Game { int computer_input; int user_input; int guessNo=0; guess_the_no_Game(){ Random random =new Random(); this.computer_input=random.nextInt(100); } public void takeUserInput(){ System.out.println("Enter your guessing no"); Scanner sc =new Scanner(System.in); this.user_input= sc.nextInt(); } boolean isCorrectNumber(){ guessNo++; if (user_input==computer_input){ System.out.println("Hurray!!! You Won. You have guessed the right no in "+guessNo+" attempts"); return true; } else if (user_input>computer_input) { System.out.println("You have guess too High..."); noOfGuess(guessNo); } else if(user_input= 10) { System.out.println("Sorry you have reached to your max chance to play game"); i = true; } } System.out.println("Do You Want To Play Again?.. Press 1 for Yes else Press any No. "); Scanner sc = new Scanner(System.in); int no = sc.nextInt(); if (no != 1) { j = false; } } } }
@Shoaib_Khan9272
@Shoaib_Khan9272 Жыл бұрын
import java.util.Random; import java.util.Scanner; class Game { int ran_num; int use_num; int No_Of_Guesses; Random random = new Random(); Scanner sz = new Scanner(System.in); public Game() { ran_num = random.nextInt(100); } public void takeUserInput() { System.out.println("Enter a number: "); use_num = sz.nextInt(); No_Of_Guesses++; isCorrectNumber(); } public void isCorrectNumber() { if (use_num == ran_num) { System.out.println("Guess Matched!!"); System.out.println("Total Guesses Taked : " + No_Of_Guesses); } else if (use_num > ran_num) { System.out.println("You have entered Greater number. TRY LOWER"); takeUserInput(); } else if (use_num < ran_num) { System.out.println("You have entered small numberr . TRY BIGGER"); takeUserInput(); } } public void hint() { System.out.println("Computer Choice: " + ran_num); } } public class tut40 { public static void main(String[] args) { Game myGame = new Game(); myGame.takeUserInput(); } }
@bhushanumbarkar8021
@bhushanumbarkar8021 Жыл бұрын
hey .... can pls make me understand how to write .... i m not getting its logic
@darshpatel5764
@darshpatel5764 Жыл бұрын
Hi harry i solved this question using recurssion but i admit that i didn't used a setter for no of guesses i hope you find it correct : import java.util.*; class OP { private int noOfGuess; private int compInput; private int userInput; Random r = new Random(); public OP() { this.noOfGuess = 0; this.compInput = r.nextInt(1000); } public void takeInput() { System.out.println("Guess number : "); Scanner sc = new Scanner(System.in); this.userInput = sc.nextInt(); this.isCorrect(); sc.close(); } public void isCorrect() { if (this.userInput == this.compInput) { System.out.println("Your guess is correct!!"); System.out.println("The number was " + this.compInput); this.noOfGuess++; return; } else if (this.compInput < this.userInput) { System.out.println("The guessed number is greater then generated number!!"); this.noOfGuess++; this.takeInput(); } else { System.out.println("The guessed number is smaller then generated number!!"); this.noOfGuess++; this.takeInput(); } } public void getGuess() { System.out.println("You took " + this.noOfGuess + " guesses!!"); } } // Main Function public class Game { public static void main(String[] args) { OP game = new OP(); game.takeInput(); game.getGuess(); } }
@learnwithatulsingh5350
@learnwithatulsingh5350 3 жыл бұрын
Sir mere paas pc nhi hai to kya hum log apne isi Android phone se Sikh or learn kre sakte hai
@learnwithatulsingh5350
@learnwithatulsingh5350 3 жыл бұрын
Please reply Sir
@abhijeetsrivastava1357
@abhijeetsrivastava1357 3 жыл бұрын
@@learnwithatulsingh5350 Nope
@ashokgawate1561
@ashokgawate1561 3 жыл бұрын
@@alvinsaini yep
@abhijeetsrivastava1357
@abhijeetsrivastava1357 3 жыл бұрын
@Tawfeeq Barik i mean if you are stupid enough to write code on android keyboard then sure, go ahead
@abhijeetsrivastava1357
@abhijeetsrivastava1357 3 жыл бұрын
@Tawfeeq Barikwelp instead of giving false hopes to anyone i generally give simple to the point ans and where did i mocked anyone lmao, i couldn't care less whether you have a pc or not
@antoniokhan6053
@antoniokhan6053 3 жыл бұрын
Love you sir from Nepal
@AdarshSingh-cb5yf
@AdarshSingh-cb5yf 3 жыл бұрын
🙏🙏😦PER DAY 😦🙏🙏 1 video of JAVA... 1 video of dsa ....
@satyamgupta6030
@satyamgupta6030 3 жыл бұрын
maan gaye guru ~ May 9,2k21 ( 11:59 pm)
@zaid6527
@zaid6527 3 жыл бұрын
Thoda late ho gya maaf krna lekin ye rha solution import java.util.Scanner; class Number_Guess_Game { public static void main(String[] args) { int number; int guess; boolean correct = false; Scanner keyboard = new Scanner(System.in); System.out.print("What is the random number: "); number = keyboard.nextInt(); while (!correct) { System.out.println("What is the Guess Number: "); guess = keyboard.nextInt(); if (guess == number) { correct = true; System.out.println("Congratulation you guess right number !!!"); } else if (guess < number) { System.out.println("Your input is higher than correct number: "); } else if ( guess > number) { System.out.println("Your input is lower than correct number: "); } } } }
@KodiLearn
@KodiLearn 3 жыл бұрын
but this is not based on OOps
@eramperwez4617
@eramperwez4617 3 жыл бұрын
Yes Zaid follow the instructions of OOPS...
@adeelferoz9131
@adeelferoz9131 3 жыл бұрын
class Game{ private int number; private int noOfGuesses; private int userNum; boolean correct; Scanner scan = new Scanner(System.in); public Game(){ Random rand = new Random(); number = rand.nextInt(100); correct = true; noOfGuesses = 0; } public void takeUserInput(){ System.out.println("Enter a number: "); userNum = scan.nextInt(); } public void isCorrectNumber(){ if(userNum == number){ correct = false; System.out.println("The number is Correct!"); }else if (userNum > number){ System.out.println("Guess a smaller number"); }else{ System.out.println("Guess a large number"); } } public void setGuess(){ noOfGuesses++; } public int getGuess(){ return noOfGuesses; } } public class Main { public static void main(String[] args) { Game play = new Game(); while(play.correct){ play.takeUserInput(); play.isCorrectNumber(); play.setGuess(); } System.out.println("Score: " + play.getGuess()); } }
@umeshchaudhary5996
@umeshchaudhary5996 2 жыл бұрын
Hi Harry, thanks for helping us with this great content I have a doubt in this program: if I'm using else condition at last in the loop it's showing "else without if " error
@arunhercules201
@arunhercules201 2 жыл бұрын
Use the else at end of that method after if loop
@mroyal8785
@mroyal8785 Жыл бұрын
If (condition){ //code }else if (condition){ //Code }else{ //code }
@abhisiktaghosh6607
@abhisiktaghosh6607 4 ай бұрын
Wow interesting game 🎮🎯😊
@soumikseal9171
@soumikseal9171 3 жыл бұрын
Sir isss bar plzzz mera naam lena solution dene k time😗😗
@soumikseal9171
@soumikseal9171 3 жыл бұрын
Solution: import java.util.Random; import java.util.*; public class Game { /* Sir I want to know how could i avoid the error that if the user enters a string or a character . Shoutout plzz!!*/ static int num, noOfGuesses; Random number = new Random(); Game() { num = (number.nextInt(10))+1; } public static int takeUserInput() { Scanner s = new Scanner(System.in); int choice = s.nextInt(); return choice; } public static boolean isCorrectNumber(int n) { if (n == num) { return true; } else { return false; } } static void setnoOfGuesses(int guesses) { noOfGuesses = guesses; } static int getnoOfGuesses() { return noOfGuesses; } static void playertype(int guess, String name) { if (guess = 3 && guess num) { System.out.println("Your guessed too high."); i++; setnoOfGuesses(i); } } } }
@kundankrishna6379
@kundankrishna6379 3 жыл бұрын
u are best bhai
@hell_robo
@hell_robo Жыл бұрын
harry bhai aapka ye video 2:44 pe stop kiya tha and mene program likhna start kar diya result dekh lena bhai please import java.util.*; public class Tut_5Game{ public static void main(String[] args) { Random rnd = new Random(); Scanner sc = new Scanner(System.in); int computer = rnd.nextInt(100); int count=0; int Guess; System.out.println("Enter Your Guessed Number :: "); Guess = sc.nextInt(); while(Guess != computer) { if(Guesscomputer) { System.out.println("You have guessed the big number.."); System.out.println("Try Again"); count++; } System.out.println("Enter Your Guessed Number :: "); Guess = sc.nextInt(); }//while over System.out.println("Computer's Generated Number.." + computer); System.out.println("You have Guessed The Correct number.." + Guess); System.out.println("Your Score is :: " + count); } };
@skg-dynamic9562
@skg-dynamic9562 11 ай бұрын
package guessThenumber; import java.util.Random; import java.util.Scanner; class Guess_game{ private int comp_num; private int user_num; private int chances; Guess_game(){ System.out.println("Welcome to number guess game: "); Random r=new Random(); comp_num=r.nextInt(100); // 0 to 99 chances=0; } void user_input(int x){ user_num=x; } void correct_number(){ if(user_num>comp_num){ System.out.println("you slected a big number: "); chances++; } else if(user_num
@atharvakori3425
@atharvakori3425 Жыл бұрын
import java.util.*; class random{ int r, input, guess = 1; Scanner sc = new Scanner(System.in); random(){ Random rand = new Random(); r = rand.nextInt(1,10); System.out.println("Guess the Random between 1 - 10 :"); } public void takeUserInput(){ input = sc.nextInt(); } public void setGuess(){ guess ++; } public int getGuess(){ return guess; } public void isCorrectNumber(){ if (input == r){ System.out.println("You guess the right number !"); } } } public class Exercise_03 { public static void main(String[] args) { // int i = 1; Scanner sc = new Scanner(System.in); random rand = new random(); rand.takeUserInput(); while(rand.r!=rand.input){ if(rand.input < rand.r){ System.out.println("Give bigger number than this."); } else { System.out.println("Give smaller number than this."); } System.out.println("Try Again !"); rand.setGuess(); // THIS IS FOR INCREMENTING THE GUESS NUMBER rand.takeUserInput(); } rand.isCorrectNumber(); System.out.println("Number of GUESS : " + rand.getGuess()); } }
@Odisha_Architects
@Odisha_Architects Жыл бұрын
Yes
@Cherry-fl4zp
@Cherry-fl4zp 2 жыл бұрын
Thank you sir!❤️
@manoor0858
@manoor0858 2 ай бұрын
//it took me so many days to understand but i finally did it :p import java.util.Random; import java.util.Scanner; class game{ int noOfGuesses=0; int guesser; Random random=new Random(); int b= random.nextInt(1,11); public void takeUserInput(){ Scanner sc=new Scanner(System.in); int a=sc.nextInt(); guesser=a; }public boolean isCorrectNumber(){ noOfGuesses++; if (guesser==b){ System.out.println("Correct"); return true; }else if (guesser>b){ System.out.println("Lower"); }else if (guesser
@akash_mishra565
@akash_mishra565 3 жыл бұрын
Awesome tutorial 💯💯
@brickapocalypse9870
@brickapocalypse9870 7 ай бұрын
Sir my answer to the question: import java.util.*; class game{ private int noOfgusses=0; public boolean a=true; public int input,ran; public int b; Scanner sc=new Scanner(System.in); public void takeUserInput() { if(a==true){ System.out.println("Enter the number for guess"); b=sc.nextInt(); input=b; IsCorrectNumberTo(); takeUserInput(); } } public game(){ ran=(int)(Math.random()*100)+1; } public void setGusses(){ noOfgusses+=1; } public int getGusses(){ return noOfgusses; } public void IsCorrectNumberTo(){ if(input==ran){ System.out.println("You have gussed the right number "+" The number of gusses you took:"+getGusses()); a= false;} else { a= true; setGusses(); if(input>ran) System.out.println(input+" is greater than the Guess"); else System.out.println(input+" The number is smaller than the Guess"); } }} public class gamer{ public static void main(String args[]){ game d=new game(); Scanner sc=new Scanner(System.in); d.takeUserInput(); }}
@sompurnamodi9031
@sompurnamodi9031 2 жыл бұрын
The best playlist!
@MindMatrixx1416
@MindMatrixx1416 25 күн бұрын
ooooooooooooo
@salmanrajpoot6822
@salmanrajpoot6822 2 жыл бұрын
Challenge excepted😄😄😄
@Mohammad_raza_01
@Mohammad_raza_01 Жыл бұрын
// Used the Recursive way to solved this problem. import javax.sound.midi.Soundbank; import java.util.Random; import java.util.Scanner; class Game{ private int comp_gen_no; private int num; int count; public void generateRandom(){ Random rn=new Random(); comp_gen_no=rn.nextInt(11); } public void setNum(int n){ this.num=n; } public void takeuserinput(){ // to take user input after wrong guess Scanner scn=new Scanner((System.in)); num=scn.nextInt(); } public boolean iscorrect(){ // to check whether the guess is wrong or right.. count++; if(num==comp_gen_no){ System.out.println("You won in "+count+"th guess"); System.out.println(); return true; } else if (num>comp_gen_no) { System.out.println(" Oooo Greater"); System.out.println("Not Guessed correctly ,Enter lesser no "); takeuserinput(); return iscorrect(); } else{ System.out.println(" Oooo Small"); System.out.println("Not guessed correctly ,Enter greater"); takeuserinput(); return iscorrect(); } } } public class CWH_43_Guess_the_number { // main class public static void main(String[] args) { Game gm=new Game(); // Game class object is initiated. gm.generateRandom(); Scanner sc=new Scanner(System.in); System.out.println("Enter the number you have guessed"); int n=sc.nextInt(); gm.setNum(n); int count=0; if(gm.iscorrect()){ System.out.println("Game End "); } } }
@shubhamkhotkar2664
@shubhamkhotkar2664 3 жыл бұрын
Harry Bhai framework ke bareme batao na....
@tejshreebopale6407
@tejshreebopale6407 2 жыл бұрын
Thank you Harry
@MKSundaram
@MKSundaram 2 жыл бұрын
Can I post my solution? Could you please tell me whether my oops implementation is right or not? Thanks
@kaaaaju
@kaaaaju 12 күн бұрын
package OOPs; import java.util.Random; import java.util.Scanner; class game{ int user; int rand; int count = 0; public game(){ Random rnd = new Random(); rand = rnd.nextInt(100); } public void takeUserInput(){ do{ Scanner scan = new Scanner(System.in); System.out.print("GUESS NO : "); user = scan.nextInt(); System.out.println(); if(user == rand){ System.out.println("CORRECT GUESS"); } else if(user > rand){ System.out.println("GUESS SMALLER NO"); }else{ System.out.println("GUESS BIGGER NO"); } count++; }while(rand != user); } public void remarks(){ if(count
@mohdumar1775
@mohdumar1775 3 жыл бұрын
Harry bhai Datat Structure ke video kab aayenge
@karthikreddy2160
@karthikreddy2160 Жыл бұрын
Same exercise used in js playlist also Bhai.. I think
@ushachoudhary736
@ushachoudhary736 3 жыл бұрын
Harry sir is the best
@masst1961
@masst1961 3 жыл бұрын
Bhai aap bahut Acha padhate hoo. Bhai safal programmer banne ke lite kya Karna parts hai uspe video banah do plz.
@teencoder8504
@teencoder8504 2 жыл бұрын
I did it! Thanks bro
@techisviral
@techisviral 3 жыл бұрын
Awesome sir
@Vivekpandey-cy1ul
@Vivekpandey-cy1ul 3 жыл бұрын
Thanks for your lesson harry bhai
@hamzariaz330
@hamzariaz330 3 жыл бұрын
Bro ap islo advance ma ly kr jy gy means kay applet,GUL , data structure and algorithm etc
@RAJAKUMAR-s4n
@RAJAKUMAR-s4n Ай бұрын
nice bro
@royfamily9273
@royfamily9273 Жыл бұрын
Thanks Harry Bhaiya
@mdanwaralam8873
@mdanwaralam8873 Жыл бұрын
helpful, thanks
@psxGaming13
@psxGaming13 3 жыл бұрын
Calculator app using java with full explanation. Please harry bhai
@shivennikhra5051
@shivennikhra5051 3 жыл бұрын
Thank you sir
@javaandmysqltutorialbysain6274
@javaandmysqltutorialbysain6274 2 ай бұрын
Challenge accepted!!: package javabasics; import java.util.Scanner; import java.util.Random; class Game{ Scanner scanner = new Scanner(System.in); Random random = new Random(); int userinput; int randint; private int attempts = 1; public Game() { randint = random.nextInt(1,101); takeUserInput(); } public void takeUserInput() { System.out.println("Take your time and try to guess the number:"); userinput = scanner.nextInt(); isCorrectNumber(); } public void isCorrectNumber() { if (userinput > randint) { System.out.println("The number you guessed is too large."); attempts++; takeUserInput(); } else if (userinput < randint) { System.out.println("The number you guessed is too small."); attempts++; takeUserInput(); } else if (userinput == randint) { System.out.println("Congrats! The number you guessed is correct."); System.out.println("You guessed the number in: " + getAttempts() + " Guesses!"); scanner.close(); } } public int getAttempts() { return attempts; } } public class Numguesser{ public static void main(String[] args) { new Game(); } }
@meghakashyap3504
@meghakashyap3504 2 жыл бұрын
very helpful
@aahutoshdwivedi6154
@aahutoshdwivedi6154 Жыл бұрын
Thank u sir ji 😌😃
@abhirupdas808
@abhirupdas808 3 жыл бұрын
//For simplicity i restricted the random number to guess) { System.out.println ("have chosen a lesser number"); no_of_guesses=no_of_guesses+1; return false; } else if (rand < guess) { System.out.println ("have chosen a bigger number"); no_of_guesses=no_of_guesses+1; return false; } else { System.out.println ("correct guess"); no_of_guesses=no_of_guesses+1; System.out.println("no. of guess required = "+no_of_guesses); return true; } } } public class Main { public static void main (String[]args) { System.out.println ("Hello World"); Scanner sc=new Scanner(System.in); game gm = new game (); System.out.println("guess a number:"); gm.userInput(sc.nextInt()); while(!gm.isCorrect ()){ System.out.println("guess a number:"); gm.userInput(sc.nextInt()); } } }
@anik2443
@anik2443 2 жыл бұрын
make use of private it makes ur code secure
@himankjeshwar8636
@himankjeshwar8636 2 жыл бұрын
@@anik2443 you can but then you need to add getters and setters to use the variable in your main method
@anik2443
@anik2443 2 жыл бұрын
@@himankjeshwar8636 security requires complexity, it reduces usability.
@shaileshhacker
@shaileshhacker 3 жыл бұрын
Thank You
@shivampanjiyara8288
@shivampanjiyara8288 3 жыл бұрын
Wow !! Means woww, how can someone Dislike his videos😑
@furqanahmadbasra5468
@furqanahmadbasra5468 7 ай бұрын
//the asnwer of the question is import java.util.Random; import java.util.Scanner; class Main { public static void main(String[] args) { System.out.println("_________________________________________________this is a number guessing game____________________________________________________________ "); int lifes = 5; //generate the random number random r_number = new random(); int n = r_number.getRandom_number(); // random number is stored in integer n System.out.println("the random number is =" + n); // the random no. is printed so we cna see if the code is working or not do { // this loop will contnue until we guess the coreect number System.out.println("you have lifes = " + lifes); //take user input for the random number takeuser_input input = new takeuser_input(); input.user_input(); int guess = input.getGuess(); // the input is stored in integer guess System.out.print(" guess number is =" + guess); //no of guess made no_of_guess n_guess = new no_of_guess(); n_guess.setValue(guess); // now to check wether the number is correct or not corect_number cheker = new corect_number(); cheker.check(guess, n); if (guess == n) { System.out.println("no of guess you made to win the game = " + n_guess.getValue()); System.out.println("congratuations😎😎😎😎😎😎🥰🥰😘🥈🏆🏆🏆 "); break; } if (--lifes == 0) { System.out.println("You ran out of lives"); System.out.println("You lose the game "); } } while (lifes > 0); } } class no_of_guess { private static int games = 0; public void setValue(int n) { games += 1; } public int getValue() { return games; } } class corect_number { public void check(int guess, int n) { if (guess == n) { System.out.println(" you have won the game "); } else if (guess < n) { System.out.println(" the number is smaller"); } else if (guess > n) { System.out.println(" the numnber is greater"); } } } class takeuser_input { private int guess; public void user_input() { System.out.print(" enter your guess : "); Scanner input = new Scanner(System.in); guess = input.nextInt(); } public int getGuess() { return guess; } } class random { private int random_number; Random rand = new Random(); int n = rand.nextInt(100); public int getRandom_number() { return n; } } // this is the code
@takshyasharma852
@takshyasharma852 3 жыл бұрын
Harry bhai aap python knjaise java m bhi projects banwaoge kya?
Java Tutorial: Exercise on Access Modifiers and Constructors
18:56
CodeWithHarry
Рет қаралды 307 М.
Java Tutorial: Exercise 3 - Solutions & Shoutouts
15:16
CodeWithHarry
Рет қаралды 211 М.
SCHOOLBOY. Мама флексит 🫣👩🏻
00:41
⚡️КАН АНДРЕЙ⚡️
Рет қаралды 7 МЛН
小丑和白天使的比试。#天使 #小丑 #超人不会飞
00:51
超人不会飞
Рет қаралды 44 МЛН
Will A Guitar Boat Hold My Weight?
00:20
MrBeast
Рет қаралды 190 МЛН
How much HTML, CSS and JavaScript is Enough to get a Job 🔥
14:32
CodeWithHarry
Рет қаралды 267 М.
AIR 1 Took his life !! 😔 | Every Student need to listen this - Alakh sir
11:13
Complete CyberSecurity Roadmap 2024 (Beginner's Guide)
15:04
CodeWithHarry
Рет қаралды 54 М.
Java Tutorial: Constructors in Java
15:53
CodeWithHarry
Рет қаралды 684 М.
Java Number Guessing Game
17:53
MrStormUMA
Рет қаралды 18 М.
Making a simple Java Program - Random Number Generator (Guess The Number game!)
14:49
xxRafael Productions - Rafael Vicuna
Рет қаралды 5 М.
Java Tutorial: Introduction to Object Oriented Programming
15:13
CodeWithHarry
Рет қаралды 832 М.