how to 开发者_开发百科have these string values in an array. its giving me the output loc[j]==1 is simple loc[j]>1 is extended. but am storing this in string.. i need to store these values in string array . how do i do it
String s = (loc[j]==1 ? "simple" : (loc[j]>1 ? "extended" : null));
this is equivalent to this code
if(loc[j]==1)
System.out.println("Simple");
else
System.out.println("extended");
- Make array of strings.
- Store strings in array.
Like so:
String[] results = new String[loc.length]; // Looks like it should be the same length as loc. If not, change it as needed.
// later on, presumably in a for loop or something
results[j] = (loc[j]==1 ? "simple" : (loc[j]>1 ? "extended" : null));
If it is single
value then no need to use array. Learn how to use Java arrays (Tutorial)
String s=null;
if(loc[j]==1) //I presume that loc is an array of int
s="Simple";
else
if(loc[j]>1)
s="extended";
精彩评论