Answer to Question #285581 in Java | JSP | JSF for kkkkkk

Question #285581

do while loop



Sample output:



1. Write a program that asks the user for a starting value and an ending



value and then writes all the integers (inclusive) between those two values.



Enter Start:



10



Enter End:



15



10



11



12



13



14



15



Sum of in range values: 75

1
Expert's answer
2022-01-09T02:21:38-0500

public class Loop {

public static void main(String[] args) {

java.util.Scanner scanner = new java.util.Scanner(System.in);

System.out.println("Enter start:");

int current = scanner.nextInt();

System.out.println("Enter end:");

int end = scanner.nextInt();

int sum = 0;

do {

System.out.println(current);

sum += current;

current++;

} while (current <= end);

System.out.println("Sum of in range values: " + sum);

}

}


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog