-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompetition1.java
More file actions
70 lines (63 loc) · 1.9 KB
/
Copy pathCompetition1.java
File metadata and controls
70 lines (63 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package com.example.Competition1;
import java.util.Scanner;
public class Competition1 {
static Scanner scanner = new Scanner(System.in);
public void nPowers(double x, int n){
for (int i = 1; i <= n; i++){
System.out.println(Math.pow(x, i));
}
}
public void sum(int n){
int sum = 0;
for (int i = 1; i <= n; i++){
sum += i;
}
System.out.println(sum);
}
public void reverseInt(int num){
int reverse = 0;
while (num != 0){
int digit = num % 10;
reverse = reverse * 10 + digit;
num = num / 10;
}
System.out.println(reverse);
}
public void inputUntil1(){
double a = scanner.nextDouble();
double b = 0;
double c = 0;
while(a != -1){
b += a;
a = scanner.nextInt();
c++;
}
System.out.println(b / c);
}
public void decoder(int a){
int b = 0;
for (int i = 1; i <= a; i = i * 10){
b++;
}
for (int i = b / 2; i >= 1; i--){
System.out.println((char)((a % (int)(Math.pow(100, i)) / (int)(Math.pow(100, i - 1)))));
}
}
public static void main(String[]args){
Competition1 runner = new Competition1();
System.out.println("Input one double and one integer");
double a = scanner.nextDouble();
int b = scanner.nextInt();
runner.nPowers(a, b);
System.out.println("Input one integer");
int c = scanner.nextInt();
runner.sum(c);
System.out.println("Input one integer");
runner.inputUntil1();
int d = scanner.nextInt();
runner.reverseInt(d);
System.out.println("Input one integer");
int e = scanner.nextInt();
runner.decoder(e);
}
}