HI,
I am new to java programming. So, while practicing some java programming. I got a very strange logical error.

Does'nt matter what the user enters, the programm always returs the result as true.
Please, tell where I am stuck:

I will be positing my code here:

import java.util.Random;
import java.util.Scanner;

public class Tanmay {

    public static void main(String... asd) {
        int b = 0;
        Random randomGenerator = new Random();
        int a = randomGenerator.nextInt(10);
        System.out.println(a);
        network n = new network();
        n.setter(a);

        Scanner d = new Scanner(System.in);

        int c;
        System.out.print("\nplease enter your guess!\n");
        c = d.nextInt();
        n.getter(a);
        System.out.print(c + "\n");
        n.checker();


    }
}
_________________________________________

//the network class:


public class network {

    private int input=0;
    private int checker=1;
public boolean again = false;

    public void setter(int a) {
        input = a;
    }

    public void getter(int a) {
        checker = a;

    }
public void checker(){
    if(input==checker)
System.out.println("its true ");
    else 
        System.out.println("its false");
}


    }

_________________________

I know, they are many unused variables. Actually when the program was not working. I tried to check the errors, by making the code more simple. That is why I have so many unused variables.

please help out the noob, with this problem..

THank you in advance.

Recommended Answers

All 2 Replies

You are passing in a for both the getter and setter. For the getter you want to pass in c.

thank you so much!
That was such a silly mistake.. :p

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.