几乎就是标题所说的.我是这个彩票号码分配的最后一点,我不知道为什么我调试时第二组if/else if语句没有显示.我知道if/else语句是互斥的 - 但是如果两个测试都不应该是if和then 这是代码.
count=0;
while(count<5)
{
if(lottery[count] == user[count])
{
lotto = lottery[count];
cout<<"So, you matched numbers with "<<lotto <<".\n";
tally++;
}
if(tally==5 && count == 5)
{
cout<<"Congratulations, you're the grand prize winner!";
}
else if(tally < 5 && count == 5)
{
cout<<"A total of "<<tally<<" of your lottery picks matched.";
}
else if(tally == 0 && count == 5)
{
cout<<"Caution. The following comment is an inside joke. Read at your own risk.";
cout<<"Bet you …Run Code Online (Sandbox Code Playgroud) 我有这个迭代器,
Set<BigFraction> key = knowledgeD.keySet();
TreeSet<BigFraction> sortKey = new TreeSet<BigFraction>();
sortKey.addAll(key);
Iterator<BigFraction> iter = sortKey.iterator();
return iter;
Run Code Online (Sandbox Code Playgroud)
BigFraction只是数据类型,如果它使得使用int或其他东西更容易.
无论如何,当我稍后调用迭代器时
while (iterator().hasNext());
Run Code Online (Sandbox Code Playgroud)
它基本上只是给了我一个无限循环的somesort ...当我打印出iterator()之前我得到了循环
java.util.TreeMap$KeyIterator@53b4b24d
Run Code Online (Sandbox Code Playgroud)
任何想法都被卡住了,
问候,
辛
我在比较双打方面遇到了问题.比较负责停止一段时间.代码运行正常,但突然之间,循环永远不会停止.将来自centroidList的dimVal的值与计算的临时变量(粗体位)进行比较.代码总是输入if,如果我使用"!="或"=="并不重要.打印出来的值,它们完全一样.怎么了?
package clusters;
import java.util.LinkedList;
public class KMeansV2 {
LinkedList<Record> table;
LinkedList<Centroid> centroidList;
LinkedList<Double> intervalList;
boolean clusterStop;
int meassureType;
int prec=10000000;
KMeansV2()
{
Read read=new Read(true,"BrCa_HD_full.xlsx");
table=new LinkedList<Record>(read.table);
centroidList=new LinkedList<Centroid>();
CreateCentroids(2);
SetMeassureType(1);
while(clusterStop==false)
{
UpdateRecords();
UpdateClusters();
}
Output();
}
public void SetMeassureType(int meassureType)
{
this.meassureType=meassureType;
}
public void CreateCentroids(int centroidCount)
{
if(centroidList.isEmpty())
{
for(int i=0;i<centroidCount;i++)
{
centroidList.add(new Centroid(table.get(0).values.size(),i));
}
}
else
{
centroidList.clear();
for(int i=0;i<centroidCount;i++)
{
centroidList.add(new Centroid(table.get(0).values.size(),i));
}
}
}
public void UpdateRecords()
{
for(int i=0;i<table.size();i++)
{
table.get(i).Update(centroidList, meassureType); …Run Code Online (Sandbox Code Playgroud) 我想知道为什么这个while循环不允许我的程序终止?
据我所知(虽然我可能错了)条件while (cin >> line)检查我的输入流是否为String然后运行我的循环,直到在输入中找不到其他字符串.然而,在测试我的代码后,我得到了正确的输出,但我的循环永远不会终止任何想法为什么?
#include <cstdlib>
#include <iostream>
#include <cctype>
using namespace std;
int main() {
string roman_digits[] = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"};
string roman_tens [] = {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"};
string roman_hundreds [] = {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"};
string roman_thousands [] = {"", "M","MM", "MMM"};
string line;
char c;
cout << "Type in a Roman numeral: ";
// …Run Code Online (Sandbox Code Playgroud) 你好,我有这个查询
$upit = "SELECT id from usluga";
$rezultat = mysql_query($upit);
while($red = mysql_fetch_object($rezultat))
{
echo "<li>{$red->id}</li>";
}
Run Code Online (Sandbox Code Playgroud)
我想在退出时得到这个:
<li>1,2,3,4,5,6</li>
<li>7,8,9,10,11,12</li>
<li>13,14,15,16,17,18</li>
<li>19,20,21,22,23,24</li>
Run Code Online (Sandbox Code Playgroud)
等等..
有帮助吗?
我正在做很多变量,但我想通过while语句来做这个.
问题是我无法弄清楚如何将变量用作变量名的一部分,以便在循环id中创建的变量不会多次创建(从而导致错误).
我有一个像这样的循环:
int index = 0
while (index < 10){
JLabel A1 = new JLabel("A" + [index]);
index++;
}
Run Code Online (Sandbox Code Playgroud)
显然我不希望我的所有变量都被称为A1,因为这不是合法的语法.我如何拥有它以使我的变量为A [index]?
只是掌握处理foreach循环.对于每一行,我在$ array中设置'vine'和'mp4'但是当我回显这些值时,它们会发布两次.这是我的代码:
$sql="SELECT vine_id,mp4_url FROM videos LIMIT 1";
$res=mysql_query($sql);
while($row=mysql_fetch_assoc($res)){
foreach ($row as $array) {
$array=array(
"vine"=>$row['vine_id'],
"mp4"=>$row['mp4_url']);
echo $array["vine"];
echo $array["mp4"];
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的输出:
bUjdjmFHt5I //vine
https://vines.s3.amazonaws.com/v/videos/2013/04/20/A42066A1-EC83-4211-BA20-DAD287C8AF1E-362-0000002797BBAC52_1.0.7.mp4?versionId=oMGICGs2c7dCbodVIHHiaQ1MhqKg65.y //mp4
bUjdjmFHt5I //vine
https://vines.s3.amazonaws.com/v/videos/2013/04/20/A42066A1-EC83-4211-BA20-DAD287C8AF1E-362-0000002797BBAC52_1.0.7.mp4?versionId=oMGICGs2c7dCbodVIHHiaQ1MhqKg65.y //mp4
Run Code Online (Sandbox Code Playgroud)
我在我的代码中遗漏了两次这个帖子吗?
我需要编写一个循环,每百万次迭代打印一次消息.我想让它运行10秒钟(时钟时间)来查看打印的语句数量.
我想我现在只是把自己绑在了结...
public class OneInAMillion{
public static void main(String []args){
long startTime = System.currentTimeMillis(); //time at start of execution
long endTime = startTime + 10000; //time at end of execution (10000 = 10 seconds)
int count = 1;
while(System.currentTimeMillis() < endTime) { //run this before 10 seconds is up
for (int i = 0; i < count; i++) {
if(i % 1000000 == 0) {
System.out.println("Iteration: " + count++); //print every millionth iteration
}
}
}
System.out.println("Time up!"); //print once …Run Code Online (Sandbox Code Playgroud) $x = 0;
$y = 0;
while ($x < 6);
{
while ($y < 6)
{
echo "INSERT INTO map_location(xLoc,yLoc) VALUES ($x,$y)";
$y++;
}
$x++;
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用PHP脚本批量生成SQL语句,以生成从0到6的x,y坐标的所有可能组合.这应该是总共49个组合,我不想一个接一个地插入它们.我正在努力弄清楚为什么这是一个无限循环.
我已经实例化了一个BufferedReader来读取输入流.它有一个布尔ready()方法,返回false直到可以读取读者.我现在有
BufferedReader br = new BufferedReader(new InputStreamReader(myProcess.getInputStream()));
try {
while (!br.ready()) {
}
String line = br.readLine();
...
} catch (IOException e) {
...
Run Code Online (Sandbox Code Playgroud)
PMD警告我的是空while块,我猜PMD是对的.我该如何重写代码?
while-loop ×10
java ×5
php ×3
c++ ×2
loops ×2
combinations ×1
conditional ×1
double ×1
for-loop ×1
foreach ×1
if-statement ×1
iteration ×1
iterator ×1
mysql ×1
pmd ×1
recursion ×1
return-value ×1
variables ×1