printing prime numbers using only loops and if statements
By : Vedant Goel
Date : March 29 2020, 07:55 AM
I wish did fix the issue. For z to be a prime number, it must be the case that there does not exist any number a such that 2 <= a <= sqrt(z) and a is a factor of z. I'd change your code to: code :
import math
y=1
z=y
while z>= 1 and z<1000 :
z= 2*y + 1
y=y+1
if all(z%a != 0 for a in range (2,int(math.sqrt(z) + 1))):
print(z)

Loops with if statements classifying numbers
By : Terry Chai
Date : March 29 2020, 07:55 AM
wish of those help No need for a (nested) loop, use the vectorised ifelse instead: code :
testing = ifelse(testing > 1, 'More', ifelse(testing < 1, 'Less', 'Same'))

Sorting out numbers in for loops
By : Shweta
Date : March 29 2020, 07:55 AM
around this issue You have an Array notprim that you can imagine as [undefined × 100], and !!undefined === false, i.e. undefined is falsy If for some number n you have notprim[n] falsy, you assume it means n must be a prime number and add it to another Array, prim code :
for (t = 0; t <= 100; t = t + n)
// t ∈ nℤ, 0 <= t <= 100

Random numbers in Java loops and if statements
By : Jackson Hunt
Date : March 29 2020, 07:55 AM
I wish this help you The problem is it prints out "guess higher" but the computer does not always guess higher. I'm not sure how to go about this problem.

Have to write a program that gives me the sum of even numbers without using if statements nor loops nor array how should
By : Janakiraman M
Date : September 03 2020, 07:00 AM
like below fixes the issue I want to write a program that makes the user enter 3 integers num1,num2,num3 and give me the sum of the even numbers entered and the average of the even numbers without using if statements/loop/arrays I'm stuck can't figure it out. , You could use streams and filter() like code :
int num1 = 2, num2 = 3, num3 = 4;
int sum = IntStream.of(num1, num2, num3).filter(x > x % 2 == 0).sum();
double count = IntStream.of(num1, num2, num3).filter(x > x % 2 == 0).count();
System.out.printf("sum of evens is %d and the average is %.2f%n", sum, sum / count);
int sum = (num1 % 2 == 0 ? num1 : 0)
+ (num2 % 2 == 0 ? num2 : 0) + (num3 % 2 == 0 ? num3 : 0);
double count = (num1 % 2 == 0 ? 1 : 0)
+ (num2 % 2 == 0 ? 1 : 0) + (num3 % 2 == 0 ? 1 : 0);

