vendredi 27 mars 2015

Java won't read my second process



I am studying Java now and I have a problem. In my scenario I created a series of methods and I asked the user to choose from one of them. After choosing the desired method there will be a message that will ask to input a string or an integer. My problem is After choosing the desired method it skipped the second phase which is asking to input any string/integer. Hope you'd understand my problem.


Here's my simple code:



import java.util.*;

import java.io.*;

public class MachineProblemChoser {

static Scanner console = new Scanner(System.in);

public static void main(String[] args) {

int chosenProblem;

System.out.println("Choose a problem you want to process");
System.out.println("***********************************************");
System.out.println(" 1 -- Sum of digit");
System.out.println(" 2 -- Days of the month");
System.out.println(" 3 -- Largest number");
System.out.println(" 4 -- Fibonacci");
System.out.println(" 5 -- Palindrome");
System.out.println(" -1 -- Exit");
System.out.println("***********************************************");
System.out.print(" Choose from(1-5) and -1 for exit: ");
chosenProblem = console.nextInt();

String numberSeries;
int inputs;

switch(chosenProblem) {

case 1:

//FROM THIS PART IT SKIPPED THE INPUT FROM THE USER
System.out.println("SUM OF DIGIT");
System.out.println("Input any integer separated by space:");
numberSeries = console.nextLine();

System.out.println("Count is: " + numberSeries.length());

break;

case 2:
//machineProblemTwo();
break;

case 3:
//machineProblemThree();
break;

case 4:
// machineProblemFourth();
break;

case 5:
//machineProblemFifth();
break;

case -1:
exitProgram();
break;

default:
System.out.println(" Oops: Choose a valid number for the selection!");

}

}


public static void machineProblemOne(String chosenNumber) {
System.out.println("Chose number are: " + chosenNumber);
}

public static int validateInput(int inputs) {

return 0;
}

public static void exitProgram() {
System.out.println(" Thanks for using the Machine Problem Choser! ");
}

}


Here's the output:



Choose a problem you want to process
***********************************************
1 -- Sum of digit
2 -- Days of the month
3 -- Largest number
4 -- Fibonacci
5 -- Palindrome
-1 -- Exit
***********************************************
Choose from(1-5) and -1 for exit: 1
SUM OF DIGIT
Input any integer separated by space: ---- From this it skipped
Count is: 0



Aucun commentaire:

Enregistrer un commentaire