Printf in Java with variable spaces [duplicate]
This question already has an answer here:
print spaces with String.format()
2 answers
I have a problem with printf in java. I would like to define the spaces with a variable.
String a = "bar";
String b ="foo";
System.out.printf("%-10s %s", b, a);
//Output:foo*7spaces*bar
The "10" should be changeable. I hope you know what I mean. Thank you guys!
java eclipse printing
marked as duplicate by Pradeep Simha, Johan, Tunaki
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Jun 14 '16 at 12:24
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
print spaces with String.format()
2 answers
I have a problem with printf in java. I would like to define the spaces with a variable.
String a = "bar";
String b ="foo";
System.out.printf("%-10s %s", b, a);
//Output:foo*7spaces*bar
The "10" should be changeable. I hope you know what I mean. Thank you guys!
java eclipse printing
marked as duplicate by Pradeep Simha, Johan, Tunaki
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Jun 14 '16 at 12:24
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
Have a look at this answer: print spaces with String.format().
– aix
Jun 14 '16 at 11:30
add a comment |
This question already has an answer here:
print spaces with String.format()
2 answers
I have a problem with printf in java. I would like to define the spaces with a variable.
String a = "bar";
String b ="foo";
System.out.printf("%-10s %s", b, a);
//Output:foo*7spaces*bar
The "10" should be changeable. I hope you know what I mean. Thank you guys!
java eclipse printing
This question already has an answer here:
print spaces with String.format()
2 answers
I have a problem with printf in java. I would like to define the spaces with a variable.
String a = "bar";
String b ="foo";
System.out.printf("%-10s %s", b, a);
//Output:foo*7spaces*bar
The "10" should be changeable. I hope you know what I mean. Thank you guys!
This question already has an answer here:
print spaces with String.format()
2 answers
java eclipse printing
java eclipse printing
edited Jun 14 '16 at 11:28
asked Jun 14 '16 at 11:23
Karle Mari
33
33
marked as duplicate by Pradeep Simha, Johan, Tunaki
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Jun 14 '16 at 12:24
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Pradeep Simha, Johan, Tunaki
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Jun 14 '16 at 12:24
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
Have a look at this answer: print spaces with String.format().
– aix
Jun 14 '16 at 11:30
add a comment |
Have a look at this answer: print spaces with String.format().
– aix
Jun 14 '16 at 11:30
Have a look at this answer: print spaces with String.format().
– aix
Jun 14 '16 at 11:30
Have a look at this answer: print spaces with String.format().
– aix
Jun 14 '16 at 11:30
add a comment |
2 Answers
2
active
oldest
votes
int length = 10;
System.out.printf("%-" + length + "s %s", b, a);
Ohh thank you so much :)
– Karle Mari
Jun 14 '16 at 11:35
add a comment |
String a = "bar";
String b ="foo";
int numspace = 10;
String space = String.format("%"+ numspace +"s", " ");
System.out.printf("%s %s %s", b,space, a);
@KarleMari i hope this is what you mean
– Seek Addo
Jun 14 '16 at 11:35
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
int length = 10;
System.out.printf("%-" + length + "s %s", b, a);
Ohh thank you so much :)
– Karle Mari
Jun 14 '16 at 11:35
add a comment |
int length = 10;
System.out.printf("%-" + length + "s %s", b, a);
Ohh thank you so much :)
– Karle Mari
Jun 14 '16 at 11:35
add a comment |
int length = 10;
System.out.printf("%-" + length + "s %s", b, a);
int length = 10;
System.out.printf("%-" + length + "s %s", b, a);
answered Jun 14 '16 at 11:32
Per Huss
2,560519
2,560519
Ohh thank you so much :)
– Karle Mari
Jun 14 '16 at 11:35
add a comment |
Ohh thank you so much :)
– Karle Mari
Jun 14 '16 at 11:35
Ohh thank you so much :)
– Karle Mari
Jun 14 '16 at 11:35
Ohh thank you so much :)
– Karle Mari
Jun 14 '16 at 11:35
add a comment |
String a = "bar";
String b ="foo";
int numspace = 10;
String space = String.format("%"+ numspace +"s", " ");
System.out.printf("%s %s %s", b,space, a);
@KarleMari i hope this is what you mean
– Seek Addo
Jun 14 '16 at 11:35
add a comment |
String a = "bar";
String b ="foo";
int numspace = 10;
String space = String.format("%"+ numspace +"s", " ");
System.out.printf("%s %s %s", b,space, a);
@KarleMari i hope this is what you mean
– Seek Addo
Jun 14 '16 at 11:35
add a comment |
String a = "bar";
String b ="foo";
int numspace = 10;
String space = String.format("%"+ numspace +"s", " ");
System.out.printf("%s %s %s", b,space, a);
String a = "bar";
String b ="foo";
int numspace = 10;
String space = String.format("%"+ numspace +"s", " ");
System.out.printf("%s %s %s", b,space, a);
answered Jun 14 '16 at 11:34
Seek Addo
1,45621227
1,45621227
@KarleMari i hope this is what you mean
– Seek Addo
Jun 14 '16 at 11:35
add a comment |
@KarleMari i hope this is what you mean
– Seek Addo
Jun 14 '16 at 11:35
@KarleMari i hope this is what you mean
– Seek Addo
Jun 14 '16 at 11:35
@KarleMari i hope this is what you mean
– Seek Addo
Jun 14 '16 at 11:35
add a comment |
Have a look at this answer: print spaces with String.format().
– aix
Jun 14 '16 at 11:30