public static void displayArray(int tab[]){
int i;
String choix; // choice
System.out.println("\n you want to see the values you entred from first position or last ?");
System.out.println("tape "P" for first , and"D" for last);
choix=sc1.nextLine(); // sc1 for nextLine , sc for nextInt to avoid buffering problems .
if(choix=="p"||choix=="P")
{ for(i=0;i<k;i++) //k is the maximum of the array(max index)
System.out.println("T["+i+"]= "+tab[i]); // why this instruction doesn't work ??
}
if(choix=="D"||choix=="d")
{for(i=k-1;i>=0;i--)
System.out.println("T["+i+"]= "+tab[i]);// this one too doesn't work
}}
public static void main(String[] args) {
// TODO Auto-generated method;stub
int tab[]=new int[4];
System.out.println(readIntArray(tab));
displayArray(tab);
}
}
我不明白为什么displayArray
无法正常工作,System.out.println
应该在检查条件后打印我的数组,但它不起作用。
答案 0 :(得分:0)
我认为它是用Java编写的。 比较字符串使用时
Add view...
而不是 ==
它应该与:
一起使用string.equals(String)
答案 1 :(得分:0)
当您比较==
时,String a = "foo";
String b = "foo";
a == b; //false
a.equals(b); //true
不仅会比较它们的值,还会比较给定的对象。例如:
equals
由于==
比较对象是否相似,String
会比较对象是否相同。另外,如果您在\"
内使用引号,则需要使用"
转义它们,因为如果您只使用String
,那么您将关闭public static void displayArray(int tab[]){
int i;
String choix; // choice
System.out.println("\n you want to see the values you entred from first position or last ?");
System.out.println("tape \"P\" for first , and\"D\" for last);
choix=sc1.nextLine(); // sc1 for nextLine , sc for nextInt to avoid buffering problems .
if(choix.equals("p")||choix.equals("P"))
{ for(i=0;i<k;i++) //k is the maximum of the array(max index)
System.out.println("T["+i+"]= "+tab[i]); // why this instruction doesn't work ??
//Your code did not even reach this point due to using unescape quotes inside a String and incorrect comparisons in your if
}
if(choix.equals("D")||choix.equals("d"))
{for(i=k-1;i>=0;i--)
System.out.println("T["+i+"]= "+tab[i]);// this one too doesn't work
//The reason is the very same as above
}}
public static void main(String[] args) {
// TODO Auto-generated method;stub
int tab[]=new int[4];
System.out.println(readIntArray(tab));
displayArray(tab);
}
}
,结果在错误。所以,你应该做这样的事情:
$ad = '{"data":[{"name":"1"}]}';
$contents = utf8_encode($ad );
$results = json_decode($contents);
var_dump($results->data);
此外,您需要构建代码,因为它本身很难阅读。