I want to create id (int), title (String), category (String) and cost (Float) for a class in Java. I used an Scanner object to read them from keyboard. But I can only read the id, after that the console do not allow me to read the title, it goes to category and then cost. Even if I type a float to cost, it throws an exception. Please help me.
package ChuoiTrongJava;
import java.util.Scanner;
public class IndexOf {
public static void main(String[] args) {
Scanner kb = new Scanner(System.in);
System.out.print("ID: ");
int id = kb.nextInt();
System.out.print("\nTitle: ");
String title = kb.nextLine();
System.out.print("\nCategory: ");
String category = kb.nextLine();
System.out.print("\nCost: ");
Float cost = kb.nextFloat();
}
}