At Westonci.ca, we provide clear, reliable answers to all your questions. Join our vibrant community and get the solutions you need. Explore thousands of questions and answers from knowledgeable experts in various fields on our Q&A platform. Join our Q&A platform to connect with experts dedicated to providing accurate answers to your questions in various fields.

Program to calculate series 10+9+8+...+n" in java with output

Sagot :

tonb

Answer:

import java.util.Scanner;

class Main {

 public static int calcSeries(int n) {

   int sum = 0;

   for(int i=10; i>=n; i--) {

     sum += i;

   }

   return sum;

 }

 public static void main(String[] args) {

   Scanner reader = new Scanner(System.in);

   int n = 0;

   do {

     System.out.print("Enter n: ");

     n = reader.nextInt();

     if (n >= 10) {

       System.out.println("Please enter a value lower than 10.");

     }

   } while (n >= 10);

   reader.close();

   System.out.printf("sum: %d\n", calcSeries(n));

 }

}