My favorites | Sign in
Project Home Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
  Advanced search   Search tips   Subscriptions

Issue 15 attachment: Try1.java (1.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
import java.util.Scanner;


public class Try1 {

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();

System.out.println("×àñòíîå = " + a/b);
System.out.println("Îñòàòîê = " + a%b);
System.out.println("Ñòîëáèê äåëåíèÿ: ");

int rr;
int zn;
boolean f=false;
while (a>=b) {
if (getN(rr(b),a)>=b) {
rr = rr(b);
} else {
rr = rr(b)+1;
}
if (!f) {
f = true;
} else {
System.out.println(getN(rr,a));
}
zn = getN(rr,a)/b*b;
System.out.println(zn);
zn = getN(rr,a) - zn;
a = setN(rr,a,zn);
}
}

// èíèöèàëèçèðîâàòü ñòàðøèå n ðàçðÿäîâ ÷èñëà a çíà÷åíèåì zn
static int setN(int n, int a, int zn) {
int result = a%(int)Math.pow(10,rr(a)-n);
result += zn*Math.pow(10,rr(a)-n);
return result;
}

//ðîçðÿäíîñòü ÷èñëà
static int rr(int a){
int cnt = 0;
while (a!=0) {
cnt++;
a/=10;
}
return cnt;
}

//âçÿòü ñòàðøèå n ðàçðÿäîâ ÷èñëà a
static int getN(int n, int a){
return a/(int)Math.pow(10,rr(a)-n);
}

}
Powered by Google Project Hosting