How to print an String variable as italicized text
Asked Answered
L

2

6

I have the following statements inside my class:

String myName = "Joe";
System.out.println("My name is " +myName);

I need the value on the variable myName to be printed as italic text.

Lacielacing answered 18/5, 2015 at 18:12 Comment(7)
Well does your console support italicized text? We have no idea where you're even trying to run it. You should normally just consider the console as a simple console output device.Squelch
https://mcmap.net/q/1773999/-eclipse-console-styling This link will help you in this regard. System.out.println("\030[3mMy name is\030[0m");Knowhow
this is a class exercise.Lacielacing
Are you trying to apply style in the console output or you are trying to use it with swing or JSP?Pint
@Hurix That's not going to work in general. For instance, in my eclipse console it just prints out garbage characters.Schuck
I'm using netBeans to code in java and my goal is to be able to see the variable content in italic when I hit the run button. I don't know if I have to import some library first in order to accomplish this.Lacielacing
yes, I need it to be shown in the console outputLacielacing
B
11

Try:

System.out.println("\033[3mText goes here\033[0m");

Which will output italic text if your console supports it. You can use [1m for bold, etc. Play around with the different values of [nm.

Bemuse answered 4/2, 2016 at 0:24 Comment(0)
P
-2

Here is an example of how to do that:

import java.io.FileWriter;
import java.io.PrintWriter;
import java.io.IOException;


public class Foo
{
public static void main(String[] args) throws IOException
{
PrintWriter out = new PrintWriter(new FileWriter("myFile.html"));
out.println("<u><i>my output</i></u>");
out.flush();
out.close();
}
}
Palaeontography answered 18/5, 2015 at 18:18 Comment(1)
It should be in the console.Timoshenko

© 2022 - 2024 — McMap. All rights reserved.