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
21
attachment: Task1.java
(1.2 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
public class Task2 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int dividend = in.nextInt();
int divider = in.nextInt();
String dividendStr = Integer.toString(dividend);
int[] dividendParts = new int[dividendStr.length()+1];
for (int i = 0; i < dividendStr.length(); i++)
{
dividendParts[i] = Integer.parseInt(String.valueOf(dividendStr.charAt(i)));
}
dividendParts[dividendStr.length()] = 0;
int totalResult = 0; //Ðåçóëüòàò
int pos = 0; //Ïîçèöèÿ â äåëèìîì
int n = dividendParts[pos];
System.out.println(dividend + " / " + divider);
System.out.println("-----------------");
while (pos < dividendParts.length)
{
while (n < divider && n != 0)
{
if (pos == dividendParts.length - 1)
{
break;
}
n = (n * 10) + dividendParts[++pos];
continue;
}
System.out.println(n);
int result = (n/divider);
totalResult = (totalResult*10) + result;
int len = n;
if (totalResult == 0)
{
System.out.println(divider);
}
else
{
System.out.println(result * divider);
}
n = n - (result*divider);
pos++;
}
System.out.println(n);
System.out.println(totalResult + " , " + n);
}
}
Powered by
Google Project Hosting