Java、扫描仪和 BlueJ。出了点愚蠢的错误

Java, Scanner and BlueJ. Something is going stupidly wrong

这是我第一次 post 来这里。我正在尝试 运行 一个非常简单的程序,但我受够了!

我尝试 运行 并在第二次输入后停止。我在某处读到你必须在使用任何输出命令之前要求输入。我认为这是我的错误但不是真的,一切看起来都很好(虽然写得不好,但我实际上才刚刚开始)。无论如何,这是代码:

import java.util.*;

public class corretorGramatical { 
  public static void main(String [ ] args) {   

     String word;
     String category;
      int i = 0;
      int numberOfWords;
      char code;

       Scanner entry = new Scanner(System.in);
      System.out.println("What is the code?");
      code = entry.nextLine().charAt(0);

    switch(code){
        case 'd':

        System.out.println ("How many words do you want to enter");
         numberOfWords = entry.nextInt();
       // entrada.nextLine();


        for(i = 1; i == numberOfWords; numberOfWords--) {
        System.out.println ("What is the word?");
        word = entry.nextLine();
        System.out.println ("What is the category?");
        category = entry.nextLine(); 
        System.out.println (word + ", " + category);
        } 
        break;

case 'g':
        System.out.println ("I only accept d");
        break;

case 'c':
      System.out.println ("I only accept d");
        break;

case 'f':
        System.out.println ("I only accept d");
        break;
  }        
}   
}

循环不好,不会发生。

for(i = 1; i == numeroDePalavras; numeroDePalavras--) {
    System.out.println ("Qual é a palavra?");
    palavra = entry.nextLine();
    System.out.println ("Qual a categoria?");
    categoria = entry.nextLine(); 
    System.out.println (palavra+categoria);
}

不知道你到底想要什么(不懂语言),但你可能想要这个:

 switch(codigo){
    case 'd':

    System.out.println ("Diga quantas palavras seu dicionario tera");
     numeroDePalavras = entry.nextInt();
   // entrada.nextLine();
    System.out.println ("Qual é a palavra?");

    for(i = 1; i < numeroDePalavras; numeroDePalavras--) {
    //Item[] itens = new Item[numeroDePalavras];
    System.out.println ("Qual é a palavra?");
    palavra = entry.nextLine();
    System.out.println ("Qual a categoria?");
    categoria = entry.nextLine(); 
    System.out.println (palavra+categoria);
  //  itens[numeroPalavras] = new Item(palavra, categoria);
    }
    break;

对上述答案稍做修改 - 您需要在 for 循环的开头将 i 定义为 int。

for(int i = 0; 

等等等