PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, August 18, 2022

[FIXED] how to show two variables output in one line in java?

 August 18, 2022     java, output, println     No comments   

Issue

Sytem.out.println("value of x , y : "+x +y);

Output will be "value of x,y : 1020" where x is 10 and y is 20

But I want to print this "value of x,y : 10 20"


Solution

Other than string concatenation , you can also use String.format to do this:

System.out.println(String.format("value of x & y : %d  %d" , x, y));

or System.out.printf:

System.out.printf("value of x & y : %d  %d\n" , x, y);


Answered By - Qiu Zhou
Answer Checked By - Cary Denson (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing