Sunday, 15 January 2012

first java program is not working -


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:

  1. Before any number, your initial amount is 0
  2. Iterate (i.e. go through the values) value From 1 to 1000
  3. If the price is divisible by 3 or 5, then add it to the sum
  4. 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