why variable x does not take the value i give and when passed to other classes becomes equal with variable in?

x does not takes the value i give it

 public static void main(String[] args) {
    int x;
    int y;
    String name= JOptionPane.showInputDialog("enter your name:");
    System.out.println("Welcome to Memory Game :  " + name);    
    String start= JOptionPane.showInputDialog("\n Please choose an option:"
    + "\n 1.basic"
    + "\n 2.double"
    + "\n 3.trio"
    +"\n 4.battle ");
    int in = Integer.parseInt(start);       
    //y=in;
    Scanner sc = new Scanner(System.in);  
    try{
     switch(in){
        case 1:
             String put= JOptionPane.showInputDialog("\n Please choose an option:"
             +"\n 1 to play solo"
             +"\n 2 to play vs 1"
             +"\n 3 to play vs 2"
             +"\n 4 to play vs 3"
             );
             int k = Integer.parseInt(start);  
             x=k; 
             Frameform f = new Frameform(in,x);        
             f.setVisible(true);            
             break;

this is the main, where x is inserted to be sent to the remaining classes of the project. The choices for x is either 1, 2, 3 or 4.

Upvotes: 1

Views: 70

Answers (1)

Akiner Alkan
Akiner Alkan

Reputation: 6872

You are taking start input at beginning for the option(basic,double etc.)

You need to assign the put variable to k like following:

int k = Integer.parseInt(put); 

The x value does take the price the value you give in.

But you give the wrong value than you think. That's why you are seing wrong value for the x

Upvotes: 1

Related Questions