1 Replies - 243 Views - Last Post: 04 March 2012 - 08:01 AM Rate Topic: -----

#1 VIPERHlr  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 85
  • Joined: 05-August 11

Switch Statement Problem

Posted 04 March 2012 - 07:49 AM

My switch statement is working incorrectly. I want to call the method inside of my switch.
Here is the code, this is my test class.

import java.util.Scanner;

public class PractiseTest {
    public static void main(String[] args) {
        Scanner kb = new Scanner(System.in);
    Arrays ma = new Arrays(); // calls class
    
    String[]name = new String[6];
    int choice;
    System.out.println("Enter choice: ");
    choice = kb.nextInt();
    
    switch(choice)
    {
        case 1:
        {
            ma.inputData(name); // calls method
        }
            break;
            
        case 2:
        {
            ma.displayData(name);
        }
            break;
            
            
    }
}
}


Sample output(does nothing):

Enter choice:
1
BUILD SUCCESSFUL (total time: 4 seconds)


Is This A Good Question/Topic? 0
  • +

Replies To: Switch Statement Problem

#2 Ryano121  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1362
  • View blog
  • Posts: 3,002
  • Joined: 30-January 11

Re: Switch Statement Problem

Posted 04 March 2012 - 08:01 AM

So whats supposed to happen in this Arrays class? How do you excactly know that the switch statement is not working or that there is a problem in the Arrays class which by the way you should immediately rename as it hides the Arrays class in java.util.

Set a breakpoint and step through your code.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1