FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
algorithm/PuzzleCoding/src/IntToString.java at master · wodgithub/algorithm · GitHub
wodgithub
algorithm
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
algorithm
/
PuzzleCoding
/
src
/
IntToString.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
26 lines (24 loc) · 638 Bytes
Breadcrumbs
algorithm
/
PuzzleCoding
/
src
/
IntToString.java
Copy path
File metadata and controls
26 lines (24 loc) · 638 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/**
* A:0, B:1, C:2, ... , AA:26, AB:27, ... , given an integer, return
* corresponding string
*/
public
class
IntToString
{
public
static
void
main
(
String
[]
args
) {
int
n
=
52
;
System
.
out
.
println
(
intToString
(
n
));
}
public
static
String
intToString
(
int
n
) {
StringBuilder
s
=
new
StringBuilder
();
n
+=
1
;
// b/c A:0
while
(
n
>
0
) {
if
(
n
%
26
==
0
) {
s
.
insert
(
0
,
"Z"
);
n
-=
26
;
}
else
{
s
.
insert
(
0
, (
char
) (
'A'
+
n
%
26
-
1
));
}
n
/=
26
;
}
return
s
.
toString
();
}
}
Back
|
FazBrowse Home
|
New Git URL