Jump to content

java code help pls

Go to solution Solved by Strayuru,

Change:

String first = lukija.nextLine();

to

int first = lukija.nextInt();

and

if(first.equals(second)) {

to

if(first == second) {

And then try again, I haven't tested it.

public class Guessinggame {
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args)
    { Random rand = new Random();
    Scanner lukija = new Scanner(System.in);
        int second  = 1;
        System.out.println("Guess the number 1 - 100");
            String first = lukija.nextLine();
        if(first.equals(second)) {
            System.out.println("Correc ");
        }
        else{
         System.out.println("Wrong ");
        }
    
        System.out.println(second);
        
        
    }
    
}

its not work

Link to comment
https://linustechtips.com/topic/857314-java-code-help-pls/
Share on other sites

Link to post
Share on other sites

Change:

String first = lukija.nextLine();

to

int first = lukija.nextInt();

and

if(first.equals(second)) {

to

if(first == second) {

And then try again, I haven't tested it.

Bespoke Software Engineer

 

Laptop: MacBook Air (13-inch, Early 2015) - 8GB RAM - Intel Core i5 1.6GHz - Intel HD Graphics 6000 1536 MB

DesktopGAMEMAX Onyx - AMD FX6300 Black Edition 6 Core (Overclocked to 4.1GHz) - GIGABYTE NVIDIA GTX 1050Ti Overclocked - MSI NVIDIA GTX 750Ti Gaming 1085MHz - HyperX Savage 8 GB 1866 MHz DDR3 - MSI 970 Gaming - Corsair CP-9020015-UK - Kingston SSDNow UV400 120 GB Solid State Drive

Link to comment
https://linustechtips.com/topic/857314-java-code-help-pls/#findComment-10673644
Share on other sites

Link to post
Share on other sites

np joe

Bespoke Software Engineer

 

Laptop: MacBook Air (13-inch, Early 2015) - 8GB RAM - Intel Core i5 1.6GHz - Intel HD Graphics 6000 1536 MB

DesktopGAMEMAX Onyx - AMD FX6300 Black Edition 6 Core (Overclocked to 4.1GHz) - GIGABYTE NVIDIA GTX 1050Ti Overclocked - MSI NVIDIA GTX 750Ti Gaming 1085MHz - HyperX Savage 8 GB 1866 MHz DDR3 - MSI 970 Gaming - Corsair CP-9020015-UK - Kingston SSDNow UV400 120 GB Solid State Drive

Link to comment
https://linustechtips.com/topic/857314-java-code-help-pls/#findComment-10673651
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×