All Questions
50 questions
0
votes
2
answers
342
views
Java - How to replace spaces of formatting with decimals in printf?
I would like to print out a list of items with a row of periods, or ellipsis, between the first text and final variable with a space on each side. So if the spacing is three or more, there should be a ...
0
votes
0
answers
129
views
Displaying JSON list data in a new line
I have a JSON and in that it has a list.Inside the list I want to show each data in a new line(something like /n for Java Strings) but I get all the data inside the list in a single line .Is this ...
1
vote
3
answers
9k
views
formatting a string :%20s
Hi I'm new to java programming
while trying to write some simple codes I saw this formatted string
I know how it works but my question is about the integer we put between % and s ...
at first i ...
-1
votes
3
answers
94
views
How to display double without truncating to float in string formatting?
I'm doing a Princeton's Algorithms course and first programming task requires to output the result in this way:
mean = 0.5929934999999997
stddev = 0....
0
votes
1
answer
116
views
How to format a string n number of times with a specified character, and then append it to another string?
As the title says, given a string, I would like to pad it (append) with n number of x character. Please see the below code. Is it possible to do that all in one String.format?
The commented line ...
-1
votes
2
answers
320
views
Can String.format remove numbers if they are zero?
I am building a stopwatch and I want to only display a field for the hours if they are >0.
At the moment I solve it like this, is there a shorter way?
String timeLeftFormatted = "";
if (hours >...
-2
votes
2
answers
411
views
Formating an integer to two digits
I am making a game and I'm trying to display the highscore. honestly I don't know what I am doing. I could really use some help.
I want to display the highscore in two digits (e.g. 01, 02, 03 ... 09, ...
-1
votes
2
answers
736
views
How to decode back formatted string?
I am formatting my string like this:
final String identity = String.format("%04X-%04X", random.nextInt(), random.nextInt(), "CORP");
Now if I know value of identity variable, is there any way I can ...
1
vote
3
answers
3k
views
String Formatting Java [duplicate]
Other languages like Python, JavaScript, and C# have simple string formatting. Does Java have it's own version of this? I did a Google search and couldn't find anything, but I'm hoping it's not the ...
-1
votes
1
answer
445
views
Using String.format to remove particular digits from an integer
Say we have a number
int number = 1234
and I want to use formatting to extract the final two digits as a string 34. How can one accomplish that?
I attempted:
String extraction = String.format("%d",...
1
vote
1
answer
214
views
Is there an efficient way to round string that has double value inside and get answer as double?
So my question is a bit confusing but still. I get an array of 8 strings from outside source that all contain doubles values inside. Those values are usually in 4 decimal places:
12345.5678
What I ...
1
vote
1
answer
7k
views
Why does sc.next() or sc.nextLine() not work inside a loop?
Question
Every line of input will contain a String followed by an integer.
Each String will have a maximum of 10 alphabetic characters, and each integer will be in the inclusive range from 0 to 999
...
-1
votes
1
answer
136
views
Insert number into String fast, by .format or .replace? [duplicate]
I just want to set a placeholder in a String to a running number in a big loop. For convenience the placeholder is %d. What is faster, using String's .format or .replace method?
0
votes
2
answers
68
views
String formatting potential string doubles or integer into integers
I receive a string from a server that sometimes is a double and sometimes is an integer. And i need it to be an integer.
When i do a Integer.parseInt(confusedStringNumber)
If its a double, it throws ...
0
votes
2
answers
139
views
Is it possible to display strings with new line inline
I have 2 strings
String str1 = "FIRST \n SECOND"
String str2 = "FIRST \n SECOND"
Is it possible for it to be displayed like this?
FIRST FIRST
...