[go: up one dir, main page]

0% found this document useful (0 votes)
3 views1 page

Unit3Assignment Question3 PDF

Uploaded by

easonshi686
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Unit3Assignment Question3 PDF

Uploaded by

easonshi686
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

package JAVA;

public class Assignment3 {


public static void main(String[] args) {
// Variable to store the sum, initialized to 0
int sum = 0;
// Variable to represent multiples of 5, initialized to 5
int multiple = 5;
// Counter for the loop, initialized to 0
int count = 0;

// Print the first number in the sum expression


System.out.print("5");

// Loop while the count is less than 9999


while (count < 9999) {
// Get the next multiple of 5
multiple += 5;
// Print the current multiple with a plus sign for the sum expression
System.out.print("+" + multiple);
// Add the current multiple to the sum
sum += multiple;
// Increment the loop counter
count++;
}

// Print the equal sign and the final sum


System.out.println("=" + sum);
}
}

You might also like