forked from allicen/Java-1000
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArithmeticProgression.java
More file actions
24 lines (22 loc) · 993 Bytes
/
ArithmeticProgression.java
File metadata and controls
24 lines (22 loc) · 993 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package arithmetic_progression;
import java.io.*;
import java.util.*;
public class ArithmeticProgression {
public static void main(String[] args) throws IOException {
ArrayList<Integer> data = new ArrayList<>(); // Входные данные
int step; // Шаг програессии
int result; // Результат вычислений
FileReader file = new FileReader("input.txt");
Scanner sc = new Scanner(file);
String str = sc.nextLine();
StringTokenizer st = new StringTokenizer(str, " ");
while (st.hasMoreTokens()){
data.add(Integer.valueOf(st.nextToken()));
}
step = data.get(1) - data.get(0); // Вычисление шага
result = data.get(0) + (data.get(2) - 1) * step; // Вычисление n-члена прогрессии
FileWriter fileOut = new FileWriter("output.txt");
fileOut.write(String.valueOf(result));
fileOut.close();
}
}