我刚刚编写了一个简单的c#代码来计算数字的阶乘,但程序却被卡在姓氏上.有人为什么会被卡住?
谢谢,
OMIN
using System;
//1. Write a program which finds the factorial of a number entered by the user.
namespace Beginner1{
class ProblemOne
{
static void Main (string[] args)
{
bool play = true;
while ( play ) {
Console.Write ("Type in the number you would like to find Factorial of: ");
int num = Convert.ToInt16( Console.ReadLine ());
int sum = 1;
for (int i = 2; i <= num; i++) {
sum = sum * i;
}
Console.WriteLine …Run Code Online (Sandbox Code Playgroud) 这可能是一个愚蠢的问题,但我似乎无法弄明白.
如果我正在使用循环并启动一个int,如c为1,我希望它以100为增量显示数字1-2000.
1
100
200
300
400
500
etc.
Run Code Online (Sandbox Code Playgroud)
我会为c = c +写些什么?
我有一个while循环,每次运行大约1000万次递增变量"day".我希望程序只在一百万天过后打印一条线(即
100万天过去了
200万天过去了
...
循环完成
到目前为止我有代码:
double dayMill; //outside the loop
...
dayMill = day/1000000; //every runthrough of the loop
Run Code Online (Sandbox Code Playgroud)
我正在考虑使用if语句
if( (int)dayMill == dayMill){}
Run Code Online (Sandbox Code Playgroud)
因为当天= 1,000,000然后daymill = 1所以作为一个int,它也是1.但这不起作用.它打印了0.0百万天...很多,直到1.0很多.....从来没有我想要的每一百万行的一行
我正在编写一个简单的Java程序,用于在学校中猜出正确的答案,当我把它带回家时,它会遇到错误.
起初我将TerminalIO.KeyboardReader更改为java.util.Scanner,现在当我通过Terminal运行它时,它返回"Incomparable types:java.lang.String and int".
有帮助吗?真的很困惑.
码:
import java.util.Scanner;
import java.util.Random;
public class guess {
public static void main(String [] args) {
Scanner keyboard = new Scanner(System.in);
Random generator = new Random();
System.out.println("I am thinking of a number from 1 to 10.");
System.out.println("You must guess what it is.");
System.out.print("Enter a guess: ");
int randomNumber = generator.nextInt(10) + 1;
String x = keyboard.nextLine();
int guessNum = 1;
while (x != randomNumber) {
System.out.println("Guess again!");
x = keyboard.nextLine();
guessNum ++;
}
System.out.println("RIGHT!"); …Run Code Online (Sandbox Code Playgroud) 这个代码块是在别人写的一个脚本中找到的,我被要求编辑.它似乎没有做任何事情......我想知道为什么它在那里,如果我删除它,如果世界某处的东西会出现严重错误..
我错过了什么吗?
//begin mystery code - i have no idea what this chunk of code is doing..
$result = mysql_query("SHOW COLUMNS FROM ".$table."");
$i = 0;
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_assoc($result)) {
$i++;
}
}
//end mystery code
Run Code Online (Sandbox Code Playgroud)
$result 没有在其他地方引用..
我有一个while循环,它扫描一组输入整数.它扫描并打印所有数字,最后用"......"跳到下一行.但是,脚本不会:执行while循环并打印TEST.
例如,我输入:3 44 62 1
打印:3 ......
44 ...
62 ...
1 ...
什么时候打印:3 ......
44 ...
62 ...
1 ...
测试
while(scanf("%d", &n) != -1) {
x[i] = n;
i++;
printf("%d", n);
printf("...\n");
}
printf("TEST");
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
我想计算函数在超过条件之前重复的次数.例如;
y=0
while(y<10) {
y=y+2
print(y)
}
[1] 2
[1] 4
[1] 6
[1] 8
[1] 10
Run Code Online (Sandbox Code Playgroud)
显然,该函数重复了5次,但我怎样才能在R中显示这个?
int i;
while(i=10)
{
printf("%d\n",i);
i=i+1;
}
Run Code Online (Sandbox Code Playgroud)
有一个程序,其中while(i = 10)表示while(1)[通常]表示while循环为true.因此它应该只打印10一次并将i的值递增1,即i变为11.但输出是无数次打印'10'.为什么会这样?我的平台是:64位Windows 7并使用32位Dev C++编译器.
我的问题是,当我运行它时,我的while循环只运行一次.这是我的代码.如果有人检查它并且可能寻找其他错误(我是编程java的新手!),我将非常感激.
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class Program {
boolean exit;
JFrame frame;
JPanel panel;
JTextField title;
JButton start;
JButton stop;
long x;
public Program() {
frame = new JFrame("Überlast your PC");
panel = new JPanel();
title = new JTextField("Überlast your PC v1.0");
start = new JButton("Start");
stop = new JButton("Stop");
x = 1;
exit = false;
stop.addActionListener(new ActionListener () {
public void actionPerformed(ActionEvent e) {
exit = true;
}});
start.addActionListener(new ActionListener () {
public void …Run Code Online (Sandbox Code Playgroud) 我试图为回文实现一个解决方案,我认为我的逻辑是正确的,但我的程序陷入了无限循环,我收到"Prep.exe已停止工作"的错误消息
int main()
{
string word, reverse;
cout << "Please enter a word to test for palindrome : ";
cin >> word;
cout << "Your word is: "<< word << endl;
int i = 0;
int size = word.length() - 1;
while (size >= 0)
{
reverse[i++] = word[size--];
//cout << reverse[i++];
}
cout << "The reversed word is: " << reverse << endl;
if (word == reverse)
cout << "It is palindrome" << endl;
else
cout << "It is …Run Code Online (Sandbox Code Playgroud)