问题描述
我不确定为什么我的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);
-
这是
cards.length()
,而不是cards.length
(length
是方法java.lang.String
,而不是属性). -
它是
System.out
(大写字母's'),而不是system.out
.参见 java.lang.System ..p> -
是
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 ++;){
-
从语法上讲,它是
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);
It is
cards.length()
, notcards.length
(length
is a method ofjava.lang.String
, not an attribute).It is
System.out
(capital 's'), notsystem.out
. See java.lang.System.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++;){
Syntactically, it is
if(rank == cards.substring(a,b)){
, notif(rank===cards.substring(a,b){
(double equals, not triple equals; missing closing parenthesis), but to compare if two Strings are equal you need to useequals()
: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循环多个变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!