Untitled
unknown
java
3 years ago
1.9 kB
11
Indexable
import java.util.*; public class testADT { static Scanner A = new Scanner(System.in); public static void main(String args[]) { /*System.out.println("enter number of variables"); int n = A.nextInt(); int arr[]=new int[n]; System.out.println("enter elements"); for(int i=0;i<n;i++){ arr[i]=A.nextInt(); } System.out.println("get sum"); int x = arr[0] + arr[2] + arr[1]; System.out.println("sum is " + x); int a = arr[0] * arr[2] * arr[1]; System.out.println("product is " + a); double b = (arr[0] + arr[2] + arr[1])/3; System.out.println("average is " + b);*/ //declare the array //enter all 3 numbers in array //get sum by adding all elements in array //get product by multiplying all elements in array //get average by adding all elements and dividing by the number of elements /*System.out.println("enter the number of terms"); int n = A.nextInt(), firstTerm = 0, secondTerm = 1; System.out.println("Fibonacci Series till " + n + " terms:"); for (int i = 0; i <= n; ++i) { System.out.print(firstTerm + ", "); // compute the next term int nextTerm = firstTerm + secondTerm; firstTerm = secondTerm; secondTerm = nextTerm; }*/ //declare first term as 0 and second term as 1 //enter number of terms //use loop to int x = A.nextInt(); int y = A.nextInt(); int count = 0; double sum = 0; for (int i = x; i <= y; i++) { if (i % 3 == 0) { System.out.print(i+", "); sum += i; count++; } } System.out.println("Average: " + sum / count); } }
Editor is loading...