这个指令做了什么?分号和while循环有什么用?
while(scanf("%s",&s [strlen(s)])== 1);
我正在研究一个程序来检查字符串是否是一个字母组合.这是完整的代码:
int main(){
char s[100];
while (scanf("%s", &s[strlen(s)]) == 1);
char big[26] = {0};
char small[26] = {0};
for (int i = 0; i < strlen(s); i++) {
if (s[i] >= 'a' && s[i] <= 'z') {
small[s[i] - 'a'] = 1;
}
else if (s[i] >= 'A' && s[i] <= 'Z') {
big[s[i] - 'A'] = 1;
}
}
for (int i = 0; i < 26; i++) {
if (!(big[i] == 1 || small[i] …Run Code Online (Sandbox Code Playgroud) 我们目前正在尝试在java中实现kmeans算法.我们的问题是:
我们正在使用该getData()方法用文件中的数据填充二维数组.在方法的while循环中,getData()我们有一个println(),在return命令之前我们有另一个.
第一个println()给出了我们从文件中获得的正确值.
第二个println()只是为我们0.0提供了该数组中的每个字段,除了arrayList[299][0].
这是为什么?
class KMeans {
// Number of clusters
int numberOfClusters = 4;
// Starting point for each cluster (these values should be better than completely random values for our given data set)
static double[] a = new double[]{-1.5, 2.0};
static double[] b = new double[]{-1.5, 7.0};
static double[] c = new double[]{1.5, 7.0};
static double[] d = new double[]{1.5, 2.0};
static double[][] …Run Code Online (Sandbox Code Playgroud) 大家好,所以这里是我的问题,因为我被困在这段代码中超过2天
我想让我的程序监视器成为一个特殊的应用程序,并等待它午餐我尝试"做和循环"但它不工作我已经检查和重新检查,我无法找到解决这个问题的方法
HWND hwnd = FindWindow(0,("my programme window name"));
do {
if(hwnd == nullptr ) { /* if the window has not beign found */
cout << "window not found!" << endl;
Sleep(1000);
system("cls");
}
}while(hwnd == nullptr);
/*******************************************************************/
starting the next code once the window of the programe has been found
Run Code Online (Sandbox Code Playgroud)
所以我的问题是我不断找到""窗口未找到!"当我首先启动我自己的程序然后午餐程序希望我尝试监控,但当我启动程序时我希望监控然后我启动我自己的程序一切正常精细
为你提供帮助---编辑问题解决了
我有一个实现的类,Runnable我在另一个窗口打开时运行的方法中启动它自己的线程,但是我在Runnable方法中只有一个while循环运行一次,我知道这是因为它只显示输出一次.这是下面的代码.
static private final int SOCKET = 2222;
static JFrame frame = new JFrame();
static private ServerSocket serverSocket;
static private Socket socket;
static private DataOutputStream out;
static private DataInputStream in;
static private ArrayList<User> users = new ArrayList<>();
static private int logged = -1;
public GameServer() {
initComponents();
}
public void runServer() {
Thread server = new Thread(new StartServer());
server.start();
}
public void addUser(int logged, Socket socket, JTextArea taOut) {
users.add(logged, new User(socket, taOut, this, logged));
Thread …Run Code Online (Sandbox Code Playgroud) 我正在阅读Kernighan Ritchie并且有这个角色计数程序,所以我尝试了实施
#include <stdio.h>
#include <stdlib.h>
int main()
{
char c;
int i;
c = getchar();
while (c != EOF)
i= i + 1;
printf("%d",i);
}`
Run Code Online (Sandbox Code Playgroud)
当我编译并运行此代码时,在输入一些字符后,之后没有输出.没有打印数字,我无法弄清楚原因.代码看起来很好.我也试过使用scanf(),但同样的事情发生了.
下一个例子是计算输入中的行数,同样的问题也存在.
通过语句在Python中途停止'while'循环的最佳方法是什么?我知道,break但我认为使用这将是不好的做法.
例如,在下面的代码中,我只希望程序打印一次,而不是两次...
variable = ""
while variable == "" :
print("Variable is blank.")
# statement should break here...
variable = "text"
print("Variable is: " + variable)
Run Code Online (Sandbox Code Playgroud)
你能帮我吗?提前致谢.
#include <iostream>
#include <string>
using namespace std;
int main()
{
char option='0';
do
{
cin >> option;
switch (option)
{
case '1':
cout << "testing 1\n";
break;
case '2':
cout << "testing 2\n";
break;
case '3':
cout << "Thank you, Have a nice day.\n";
break;
default:
cout << "Invalid option, Please enter option (1-3).";
}
}while (option != 3);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我不知道为什么while循环是无限的.当我键入时3,它应该打印出来Thank you, Have a nice day.并退出循环while (option != 3).但是,似乎while循环不起作用.
我有以下方法:
public int quickFind (int[] nums, int lo, int hi) {
if (lo >= hi)
return -1;
int gard = nums[lo];
int i = lo + 1, j = hi + 1;
while (true) {
while (nums[++i] < gard) {
if (i == hi) {
System.out.println("break " + i + " / " + hi + " ->" + (i == hi));
break;
}
}
while (gard < nums[--j]) {
if (j == lo)
break;
}
if (i > j) …Run Code Online (Sandbox Code Playgroud) 有人可以帮我一个循环吗?因为它不起作用
这是我的代码:
$signup = "SELECT * FROM ISPD_signup WHERE ID_user = " .$id;
Run Code Online (Sandbox Code Playgroud)
这是我的表:
如果我删除mysqli_fetch_array($alleleden)它的时间只会读出一个注册的成员,如果我离开,它将不会读出任何内容.
$alleleden = mysqli_query($mysqli, $signup);
if (mysqli_num_rows ($alleleden) == 0)
{
echo "<p>Er zijn geen inschrijvingen gevonden! </p>";
}
else
{
echo "<h4>Inschrijvingen: </h4>";
echo "<table>";
echo "<tr>";
echo "<th class='hide'>ID </th>";
echo "<th>Naam </th>";
echo "<th>Beslissing </th>";
echo "</tr>";
while ($lid = mysqli_fetch_array($alleleden));
{
echo "<tr>";
echo "<td class='hide'>" . $lid['ID'] . "</td>";
echo "<td>" . $lid['Naam'] . "</td>";
echo "<td>" . $lid['Beslissing'] …Run Code Online (Sandbox Code Playgroud) 基本上我想要的是让程序运行并在开始时重新开始,直到键入命令.我有重复部分工作,但是当我想要它时,我无法让循环中断.我试图使用if语句来获取输入并使用它来打破循环.我已经在教程中看到过它,但我无法让它为我工作.我理解break语句是退出一个循环,我想知道是否可以在if语句中使用break语句,如下所示:
while True:
i == input('Type a letter:') #They type a letter
if i == quit: #If they type "quit" this executes
print('Goodbye') #The program says goodbye
break #Ends the loop
else:
print("Your letter is", i) #If they type anything else, it gets printed
Run Code Online (Sandbox Code Playgroud)
有了它,它只是打印,:
Type a letter: quit
Your letter is quit
Goodbye
Type a letter:
Run Code Online (Sandbox Code Playgroud)
如果我输入它,不打破循环.如果不可能的话,是否有人有另一种方法可以得到相同的结果,当我输入类似"退出"的东西时,循环结束?任何帮助表示赞赏.