mercredi 25 février 2015

How to Write a Summation of Fives in Java



I need to write a program in Java that can take the multiples of five up to a value given by the user, and then add all of the multiples together. I need to write it with a while loop.


Here's what I have so far:



import java.util.Scanner;

public class SummationOfFives {
public static void main(String[] args){

//variables
double limit;
int fives = 0;

//Scanner
System.out.println("Please input a positive integer as the end value: ");
@SuppressWarnings("resource")
Scanner input = new Scanner(System.in);
limit = input.nextDouble();

//While Loop
while ((fives+5)<=limit)
{
fives = fives+5;
System.out.println("The summation is: "+fives);
}
}
}


When I run this program however, all it gives me is the multiples:



Please input a positive integer as the end value:
11
The summation is: 5
The summation is: 10



Aucun commentaire:

Enregistrer un commentaire