My favorites
▼
|
Sign in
kpi-java-training-6
KPI Java Training fall 2013
Project Home
Wiki
Issues
Source
Export to GitHub
READ-ONLY: This project has been
archived
. For more information see
this post
.
Search
Search within:
All issues
Open issues
New issues
Issues to verify
for
Advanced search
Search tips
Subscriptions
Issue
20
attachment: DivisioIInAColumn.java
(4.1 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
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
package gl;
import java.util.*;
public class DivisioIInAColumn {
public static void divisioIinAColumn(String [] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Введите делимое число ");
long a = sc.nextLong();
System.out.println("Введите делитель ");
long b = sc.nextLong();
System.out.println("");
long timeA = a;
int counterA = 0;
int m = 10;
long quotTest = 0;
long quot = 0;
int newA = 0;
int testA = 0;
String spc = " ";
String spcSumOf = "";
String spcSumAfter = "";
String min;
int n1;
// Выясняем сколько значное делимоге число;
while (timeA > 0) {
timeA /= m;
counterA++;;
}
// Формируем масив для каждой отдельной цифри делимого числа в том же порядке что й написано число;
int arrA[] = new int[counterA];
// Заполняем масив соотвецтвенными числами;
timeA = a;
do {
--counterA;
arrA[counterA] = (int) timeA % m;
timeA /= m;
}
while (counterA > 0);
System.out.println();
// Для вывода на экран красивого деления в столбик нужен массив String.
int wtf = 0;
for (int j = 0; j < arrA.length; j++) {
testA = testA * 10 + arrA[j];
if (testA < b) {
continue;
}
else {
quotTest = (quotTest * 10) + ((long) testA) / b;
wtf++;
testA = testA % (int) b;
}
}
System.out.println();
String st[] = new String[wtf * 3 + 1];
wtf = 1;
st[0] = a + "|" + b;
st[1] = "|--------";
st[2] = "|";
int p = 0;
int n = 0;
// Выполняем деление в столбик;
for (int i = 0; i < arrA.length; i++) {
min = "-";
newA = newA * 10 + arrA[i];
if (newA < b) {
quot *= 10;
continue;
}
else {
quot = (quot * 10) + ((long) newA) / b;
for (int j = 1; j <= arrA.length - i - 1; j++) {
spcSumAfter += spc;
}
m = 1;
while (newA / m > 0) {
p++;
m *= 10;
}
m = 1;
n1 = p;
while (n1 - 1 > 0) {
n1--;
min += min;
}
//Заполняем стринговый массив для вывода на экран
if (wtf == 1) {
st[wtf] = (int) (newA / b) * b + spcSumAfter + st[wtf];
st[wtf + 1] = min + spcSumAfter + st[wtf + 1];
wtf += 2;
}
else {
st[wtf] = spcSumOf + (int) newA;
st[wtf + 1] = spcSumOf + (int) ((newA / b) * b);
st[wtf + 2] = spcSumOf + min;
wtf += 3;
}
n = p;
while ((newA % b) / m > 0) {
m *= 10;
n--;
}
while (n > 0) {
n--;
spcSumOf += spc;
}
p = 0;
newA = newA % (int) b;
}
}
if (newA > 0) {
st[wtf] = spcSumOf + newA;
}
else {
st[wtf] = spcSumOf + 0;
}
st[2] += quot;
for (int i = 0; i < st.length; i++) {
System.out.println(st[i]);
}
}
}
Powered by
Google Project Hosting