loev139
V2EX  ›  Java

equals 语句判断 string,返回值问题

  •  
  •   loev139 · Feb 17, 2016 · 4081 views
    This topic created in 3926 days ago, the information mentioned may be changed or developed.

    代码如下:
    package homw;
    import java.util.*;
    public class capitol_method {
    Scanner input = new Scanner(System.in);

    int done = 0;
    int wrong = 0;
    int correct = 0;
    String[][] spc = {
           {"MONTGOMERY","AlABAMA"},
           {"JUNEAU","ALASKA"}
    

    };

    public void guess (){
    
    
    
    
        for (int i=0; i<50; i++){
    
    
        while (done == 0 && i<50){
        String capitol = input.next();
        String upp2 = capitol.toUpperCase();
    
        if (!spc[i][1].equals(upp2)){
         wrong = wrong + 1;
    
    
        }else{
        correct = correct + 1;
    
        }
      System.out.println("wong"+wrong);
        System.out.println("correct"+correct);
        System.out.println("spc"+spc[i][1]);
        }   
    
    }
    
    }
    
    }
    
    debug 返回的 spc 和输入的一摸一样。但是 wrong 变量的数值却在增加。
    
    5 replies  •  2016-02-19 08:22:37 +08:00
    hx1997
    hx1997
    Feb 17, 2016
    1
    ALABAMA not AlABAMA maybe?
    loev139
    loev139
    OP
    Feb 17, 2016
    2
    @hx1997 我擦,真是,手抖的不行
    yuriko
    yuriko
    Feb 18, 2016
    3
    写 Java 我好久不用数组了……
    loev139
    loev139
    OP
    Feb 18, 2016
    4
    @yuriko array 很重要的,你现在写什么程序
    yuriko
    yuriko
    Feb 19, 2016
    5
    @loev139 绝大多数情况都可以用 List 代替,减少了很多索引处理上的问题
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   4294 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 71ms · UTC 08:26 · PVG 16:26 · LAX 00:26 · JFK 03:26
    ♥ Do have faith in what you're doing.