本文介绍了Java for循环多个变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定为什么我的Java代码不会编译,任何建议都会受到赞赏.

 字符串等级= card.substring(0,1);字符串西装= card.substring(1);字符串卡="A23456789TJQKDHSCl";String []名称= {王牌",两个",三个",四个",五个",六个",七个",八个",九",十",杰克",皇后",国王",钻石",心脏",黑桃",俱乐部"};字符串c =";for(int a = 0,b = 1; a< cards.length-1; b = a + 1; a ++;){if(rank === cards.substring(a,b){c + = name [a];}}system.out.println(c); 
解决方案
  1. 这是 cards.length(),而不是 cards.length ( length 方法 java.lang.String ,而不是属性).

  2. 它是 System.out (大写字母's'),而不是 system.out .参见 java.lang.System ..p>

  3.   for(int a = 0,b = 1; a< cards.length()-1; b = a + 1,a ++){ 

    不是

      for(int a = 0,b = 1; a< cards.length-1; b = a + 1; a ++;){ 

  4. 从语法上讲,它是 if(rank == cards.substring(a,b)){,而不是 if(rank === cards.substring(a,b){(双等于,不是三等于;缺少右括号),但是要比较两个字符串是否相等,您需要使用 equals(): if(rank.equals(cards.substring(a,b))){

您可能应该考虑下载 Eclipse ,是Java开发的集成开发环境(不仅如此).Eclipse会在您键入时向您显示错误,并提供了修复这些错误的帮助.这样可以更轻松地开始Java开发.

I'm not sure why my Java code wont compile, any suggestions would be appreciated.

   String rank = card.substring(0,1);
    String suit = card.substring(1);
    String cards = "A23456789TJQKDHSCl";
    String[] name = {"Ace","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Jack","Queen","King","Diamonds","Hearts","Spades","Clubs"};
    String c ="";
    for(int a = 0, b = 1; a<cards.length-1; b=a+1; a++;){
        if(rank===cards.substring(a,b){
            c+=name[a];
        }


    }
    system.out.println(c);
解决方案
  1. It is cards.length(), not cards.length (length is a method of java.lang.String, not an attribute).

  2. It is System.out (capital 's'), not system.out. See java.lang.System.

  3. It is

    for(int a = 0, b = 1; a<cards.length()-1; b=a+1, a++){
    

    not

    for(int a = 0, b = 1; a<cards.length-1; b=a+1; a++;){
    

  4. Syntactically, it is if(rank == cards.substring(a,b)){, not if(rank===cards.substring(a,b){ (double equals, not triple equals; missing closing parenthesis), but to compare if two Strings are equal you need to use equals(): if(rank.equals(cards.substring(a,b))){

You should probably consider downloading Eclipse, which is an integrated development environment (not only) for Java development. Eclipse shows you the errors while you type and also provides help in fixing these. This makes it much easier to get started with Java development.

这篇关于Java for循环多个变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 04:03