-
Notifications
You must be signed in to change notification settings - Fork 0
/
thing.java
126 lines (111 loc) · 3.1 KB
/
thing.java
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import java.util.Scanner;
public class thing {
static long timeout = 500;
static int num = 243079824;
public static void main(String[] args) {
// a
System.out.println("\na");
int sum = 0;
for (int i = 2; i <= 100; i += 2) {
sum += i;
}
System.out.println(sum);
// b
System.out.println("\nb");
sum = 0;
for (int i = 1; i <= 100; i++) {
sum += i * i;
}
System.out.println(sum);
// c
int sum1 = 0;
System.out.println("\nc");
for (int i = 0; i <= 20; i++) {
sum1 += Math.pow(2, i);
}
System.out.println(sum1);
// d
System.out.println("\nd");
Scanner in = new Scanner(System.in);
System.out.print("Enter a: ");
int a = in.nextInt();
System.out.print("Enter b: ");
int b = in.nextInt();
sum = 0;
for (int i = a; i <= b; i++) {
if (i % 2 == 1) {
sum += i;
}
}
System.out.println(sum);
// e
System.out.println("\ne");
int input = num;
int sum2 = 0;
for (int i = 0; i < ("" + input).length(); i++) {
int num2 = Integer.parseInt(("" + ("" + input).charAt(i)));
if (num2 % 2 == 1) {
sum2 += num2;
}
}
System.out.println(sum2);
// 6.3
// a
System.out.println("\n6.3");
int num1, num2, num3, num4, num5, num6, num7, num8;
num1 = 18;
num2 = 12;
num3 = 21;
num4 = 1;
num5 = 5;
num6 = 8;
num7 = 20;
num8 = 22;
int[] nums = { num1, num2, num3, num4, num5, num6, num7, num8 };
System.out.println("\na");
int smallest = num1;
int largest = num1;
for (int i = 0; i < nums.length; i++) {
if (nums[i] < smallest) {
smallest = nums[i];
} else if (nums[i] > largest) {
largest = nums[i];
} else {
continue;
}
}
System.out.println("Smallest: " + smallest);
System.out.println("Largest: " + largest);
// b
System.out.println("\nb");
int even = 0;
int odd = 0;
for (int i = 0; i < nums.length; i++) {
if (nums[i] % 2 == 1) {
odd++;
} else {
even++;
}
}
System.out.println("Evens: " + even);
System.out.println("Odds: " + odd);
// c
System.out.println("\nc");
int total = 0;
for (int i = 0; i < nums.length; i++) {
int num = nums[i];
total += num;
System.out.println(total);
}
// d
System.out.println("\nd");
for (int i = 0; i < nums.length - 1; i++) {
int number1 = nums[i];
int number2 = nums[i + 1];
if (number1 == number2) {
System.out.println(number1);
}
}
in.close();
}
}