M
M
mazinkaiser2016-01-20 20:12:03
Java
mazinkaiser, 2016-01-20 20:12:03

How to add variables to a certain place, more convenient?

Hello.
I just started learning JAVA, before that I was learning C#.
So in C#, you can display variables like this:
In order not to write like this:
Console.WriteLine("His name was" + name + ", and he was " + age);
You can do this:
Console.WriteLine("His name was {0}, and he was {1}", name, age);
Question - is it possible somehow in JAVA?
Full:

public class Main {

    String name;
    String age;

    public static void main(String[] args) {

        Main pig = new Main();
        pig.name = "Alfred";
        pig.age = "2 mounths";

        System.out.println("Name: {0}, age {1}", name, age);
    }
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
MiiNiPaa, 2016-01-20
@mazinkaiser

https://docs.oracle.com/javase/tutorial/java/data/...

A
Alexey Cheremisin, 2016-01-20
@leahch

I would like to add to the previous speakers. Try logging systems like slf4j, log4j or logback. All three are absolutely amazing!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question