while-loop

Write a program to sum all the integers between 1 and 1000, that are divisible by 13, 15 or 17, but not by 30 [closed]

和自甴很熟 提交于 2020-06-29 08:57:08
问题 Closed. This question needs debugging details. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . Improve this question This my code i don't know what to do next I'm totally beginner int number = lb; while(number <= ub){ if (number % 7 == 0 && number % 15 == 0 && number % 17 == 0 && number % 30 != 0 ){ sum+= number; } number++; } System.out.println("Answer: " + sum); } } 回答1: You have to do

Determining winner in Rock Paper Scissors [python]

别来无恙 提交于 2020-06-17 09:40:32
问题 I'm a beginner in python trying to create a RPS game where human is playing against a computer. The game is created such that it would be played over a number of determined rounds (best of 3 rounds). A draw is considered a point for each side. My problem is setting the while condition. Initially I did this: while (player_count + computer_count) != winning_score : where the game ends when all round are played. However there will be instances where not all rounds needs to be played and the

How would I approach Parallel Arrays to store different types of information in java

旧街凉风 提交于 2020-06-17 08:03:51
问题 I have the following task which is that: There may be up to ten teams. Parallel Arrays are used to store the team Names, as well as to keep track of the number of Wins, Overtime Losses, and Points. After the result for the last team is entered, the program outputs a summary of each team's record in the opposite order to which they were entered. Note: "W" is worth 2 points, "L" is worth 0 points, "O" is worth 1 point Sample input: 3 //Option number Toronto //phrase W //letters that loop in a

Print all the combination of substrings from a given string in order by letter

守給你的承諾、 提交于 2020-06-13 09:23:25
问题 This question has been asked and answered plenty of times before. However, I'm specifically asking for the substrings to be printed in the specific order by each letter as shown in the output. import java.util.*; public static void main(String[] args) { breakWordIntoPieces("ABIGWORD"); } public static void breakWordIntoPieces(String str) { if (str.length() > 1) // I'm skipping all substrings of less than 2 letters { List<String> fragments = breakWordIntoPiecesFromRightToLeft(str); for (String

Strange while loop behavior

折月煮酒 提交于 2020-05-24 03:56:25
问题 How is it that when I uncomment "//cout << current << endl;" in the code below, it works? #include <iostream> #include <float.h> using namespace std; int main() { char divider = 2; float power = 1; float number = 1; float current = number + power; cout.precision(1024); // Divide until rounded off while(current != number) { power /= divider; current = number + power; //cout << current << endl; } cout << power * divider << endl; cout << FLT_EPSILON << endl; } The code above prints: 1

Python How to Return value in while loop

纵然是瞬间 提交于 2020-05-08 14:57:52
问题 When put return in while loop the loop will stop How to fix it? ser = serial.Serial( port='COM5', baudrate = 9600, timeout=1) while 1: x=str(ser.readline()) x = re.findall("\d+\.\d+", x) x = float(x[0]) return(x) #loop stopped print(x) Could you please help me? 回答1: Simply take your x=str(ser.readline()) x = re.findall("\d+\.\d+", x) x = float(x[0]) return(x) #loop stopped put it into a function like def foo(ser): x=str(ser.readline()) x = re.findall("\d+\.\d+", x) x = float(x[0]) return(x)

Wait for button to be pressed JAVA GUI

孤人 提交于 2020-04-30 06:58:04
问题 At the moment I'm currently re-writing a text-based program to have a GUI. One of the problems I am experiencing is that I want the program to wait until a certain condition is met. This condition can be met through the user clicking the "Walk" button until the player.walked attribute = 5. When using a text-based interface this is quite simple, use a while loop and inside have an input function. while (player.getWalked() < 5) { //wait for user input via terminal through the scanner. } However

Generating random number with different digits

我只是一个虾纸丫 提交于 2020-04-30 05:21:31
问题 So I need to write a program which generates random numbers from 100 to 999, and the tricky part is that the digits in the number can't be the same. For example: 222 , 212 and so on are not allowed. So far, I have this: import random a = int (random.randint(1,9)) <-- first digit b = int (random.randint(0,9)) <-- second digit c = int (random.randint(0,9)) <-- third digit if (a != b and a != b and b != c): print a,b,c As you can see, I generate all three digits separately. I think it's easier

Generating random number with different digits

岁酱吖の 提交于 2020-04-30 05:20:10
问题 So I need to write a program which generates random numbers from 100 to 999, and the tricky part is that the digits in the number can't be the same. For example: 222 , 212 and so on are not allowed. So far, I have this: import random a = int (random.randint(1,9)) <-- first digit b = int (random.randint(0,9)) <-- second digit c = int (random.randint(0,9)) <-- third digit if (a != b and a != b and b != c): print a,b,c As you can see, I generate all three digits separately. I think it's easier

Divide two integers without using multiplication, division and mod operator in java

一曲冷凌霜 提交于 2020-04-14 09:05:03
问题 I write down a code which find out quotient after dividing two number but without using multiplication,division or mod operator. My code public int divide(int dividend, int divisor) { int diff=0,count=0; int fun_dividend=dividend; int fun_divisor=divisor; int abs_dividend=abs(dividend); int abs_divisor=abs(divisor); while(abs_dividend>=abs_divisor){ diff=abs_dividend-abs_divisor; abs_dividend=diff; count++; } if(fun_dividend<0 && fun_divisor<0){ return count; } else if(fun_divisor<0||fun