我的头不再工作了.我必须尽快完成这个如何使循环更短.
目前我有4个不同的for循环.我想把它们结合起来,只有一个.
Card[] cards = new Card[4*13];
void testCreateCards() {
int k = 0;
for (int suit = 0; suit <= 3; suit++) { // for suit
for (int value = 1; value <= 13; value++) { // from Ace to King
// build new card
cards[k++] = new Card(suit, value);
}
}
}
void testDrawClubs() {
int x = 0;
int y = 0;
for (int i = 0; i <= 12; i++) {
cards[i].displayCard(x, y);
x +=80;
} …Run Code Online (Sandbox Code Playgroud) 你能解释一下这个for循环是如何工作的吗?
for (int i = 0, ii = deck.size(); i != ii;) {
int x = i % NUMBER_OF_CARDS;
int y = i / NUMBER_OF_CARDS;
Card d = deck.get(i++);
d.setFace(true); // face up
d.displayCard(40 + x * 90, y * 140 + 10); // draw them
println(d.getRank()); // println
text("Value:" + d.getRank() + " of " + d.getSuit(), 40+x * 90, y * 140 + 120);
}
Run Code Online (Sandbox Code Playgroud) 我的计算不正常.我看不出代码有什么问题.有时它不能正确计算得分.有时它完美无缺.我甚至不能理解它什么时候做得正确以及什么时候做得不好.
分数计算应该是这样的:
Ace可以将总分增加到1或11.如果分数高于21,则ace计算为1; 否则ace是11.
这是我的代码:
// Updates the the value of the cards the player has in their hand
int updateValueOfHand() {
int result = 0; // it will be returned
int ace = 0; // value of ace
for (int i =0; i < playerHand.size(); i++) // loop to see players hand
{
int cardValue; // card value of hand
Card card=(Card)playerHand.get(i); // check the card
cardValue = card.getRank();
if (cardValue == 1) // if card value is 1 …Run Code Online (Sandbox Code Playgroud) 我试图将一个类作为参数传递给方法,但不知道是否可能.
而不是调用的Insertion class在所述void runTest(String[] text, int[] number, String url)方法中,可以我通过它作为一个参数,这样我可以添加其他的排序算法.
这是我到目前为止:
Insertion insertion;
void setup() {
String url = sketchPath("numbers/512/");
insertion = new Insertion();
String[] stringData = null;
int[] intData = null;
runTest(stringData, intData, url);
}
void runTest(String[] text, int[] number, String url) {
File directory = new File(url);
File[] listOfFiles = directory.listFiles();
for (File file : listOfFiles) {
//println(file.getName());
text = loadStrings(file);
number = int(text);
insertion.insertionSort(number);
}
}
class Insertion {
Insertion() {
}
int[] insertionSort(int[] …Run Code Online (Sandbox Code Playgroud) 当我做:
while [ $choice != 'X' ]
do
Run Code Online (Sandbox Code Playgroud)
它工作,但当我这样做
while [ $choice != 'x' ] || [ $choice != 'X' ]
do
Run Code Online (Sandbox Code Playgroud)
他们都没有工作.
任何的想法?
我不能以我想要的方式获得这个SQL查询.我试图匹配使用"喜欢"和"和"的记录,但我没有得到任何结果.当我将其更改为"或"时,我得到了结果.
为什么我使用时没有得到任何结果?
SELECT a.MOD_REQ_NUM,
a.REFERENCE_CODE,
a.REFERENCE_VALUE,
a.ACTIVE_DETAIL,
b.REQUESTOR_WWID,
b.REQUEST_DATE
from DB_MOD_REQ_DETAILS a, DB_MOD_REQ_HEADER b
where a.MOD_REQ_NUM=b.MOD_REQ_NUM
and a.ACTIVE_DETAIL='Y'
and b.ACTIVE_HEADER='Y'
----------------------------------------------------------
and
(a.REFERENCE_VALUE like '%43598%' and a.REFERENCE_CODE = 2)
and
(a.REFERENCE_VALUE like '%3694894%' and a.REFERENCE_CODE = 4)
Run Code Online (Sandbox Code Playgroud)

我希望只能在给定的a.REFERENCE_CODE中搜索a.REFERENCE_VALUE.我有表单字段和C#foreach循环.每个字段都有自己的REFERENCE_CODE.如果用户正在搜索1个字段,我想这样做:
(a.REFERENCE_VALUE like '%43598%' and a.REFERENCE_CODE = 2)
Run Code Online (Sandbox Code Playgroud)
如果用户正在搜索多个字段,我想匹配:
a.REFERENCE_VALUE like '%43598%' and a.REFERENCE_CODE = 2
and
a.REFERENCE_VALUE like '%3694894%' and a.REFERENCE_CODE = 4
Run Code Online (Sandbox Code Playgroud)
这是包含所有数据的查询的屏幕截图
