Advertisement
Uimin_Maxim

Задача 5

Jan 27th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.26 KB | None | 0 0
  1. //Уймин Максим
  2. //IT School, 2 группа
  3. //09.10.2015
  4. //Задача 5. Заполнить массив значениями членов арифметической прогрессии по формуле, заданной учителем
  5. import java.io.PrintStream;
  6. import java.util.Scanner;
  7. public class Exercise_5 {
  8.     public static PrintStream out = System.out;
  9.     public static Scanner scan = new Scanner(System.in);
  10.     public static void MainFunction (){
  11.         //Функция создаёт массив и заполняет его членами арифметической прогресси по формуле, введённой с клавиатуры
  12.         out.println("Enter the array size(intger number, greather then zero)");
  13.         int N = scan.nextInt();
  14.         int[] array=new int [N];
  15.         out.println("Formula of arithmetic progression is a[n] = a[1] + d(n-1)");
  16.         out.println("Enter the a[1]");
  17.         int a = scan.nextInt();
  18.         out.println("Enter the d");
  19.         int d = scan.nextInt();
  20.         for (int i=0;i<N;i++){
  21.             array[i] = a;
  22.             a = a+d;
  23.             out.print(array[i]+"\t");
  24.         }
  25.     }
  26.     public static void main (String [] args){
  27.         //Основная функция, отсюда начинается выполнение приложения
  28.         MainFunction();
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement