Click here to Skip to main content
15,908,634 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I am selecting a method using switch case and in method asking for input in two different statement but both stm printing together.And if i am using same thing with 'if else' in place of switch it is proper working.Can any one tell what is the problem.
C#
public void startmethod() throws Exception {
        System.out.println("1. for copy and paste");

C#
choice = kb.nextInt();
        switch (choice) {
        case 1:
            copyandpaste.selectOption();
            break;


C#
public void selectOption() throws Exception {
        System.out.println("1. Text file");

C#
switch (choice) {
        case 1: {
            this.copyAndPasteTxt();
            break;


C#
public void copyAndPasteTxt() throws Exception {
        System.out.println("enter source loc");
        src = kb.nextLine();

File file=new File(src);
if((file.exists())==true){

then it prints the print statement and without waiting for input it prints the else statement.
Posted
Updated 8-Dec-14 22:14pm
v4
Comments
Fredrik Bornander 8-Dec-14 8:30am    
Have you forgotten the break statement?
Richard MacCutchan 8-Dec-14 8:56am    
I cannot see how that would even compile.
Richard MacCutchan 9-Dec-14 4:33am    
You have edited this question, but you are only showing small extracts of your code. Show us the complete block where the error occurs.
bh@r@t 9-Dec-14 5:47am    
I got the answer !!!!!!!!!!!!!!!!!!!!!!!!! :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900