I'm new to java
, this is my first attempt to write a program: I need it Write a program that prints the sum of all positive integers less than 1000, which is divided by 3 or 5. This is my (bad) attempt. After compiling it is only getting the number and showing them:
import java.util.Scanner; Public class ex1 {public static zero main (string [] args) {int num = 1; Int count = 1; While (calculation
Used for a while, I think you can I do not know in Loops, so I would like to avoid using it.
Your code should be:
- Before any number, your initial amount is 0
- Iterate (i.e. go through the values) value From 1 to 1000
- If the price is divisible by 3 or 5, then add it to the sum
- Print the amount.
issue1):
int sum = 0;
point 2):
int value = 1; While (value & lt; = 1000) {// do point 3 value ++; } (Value% 3 == 0)) (value% 5 == 0)) {sum = sum + value; }
issue 4):
System.out.println (sum);
By putting it together:
int sum = 0; Int value = 1; While (value
For calculating the value of your main error amount and time position, use the calculation. There is also a mistake in the form of a pipe or any mistake.
Hope this helps
No comments:
Post a Comment