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.

Mureinik
  • 297,002
  • 52
  • 306
  • 350
LH7
  • 1,385
  • 2
  • 12
  • 16
  • 6
    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. – Jon Skeet May 18 '15 at 18:14
  • 1
    http://stackoverflow.com/questions/26132541/eclipse-console-styling This link will help you in this regard. System.out.println("\030[3mMy name is\030[0m"); – newstackoverflowuser5555 May 18 '15 at 18:15
  • this is a class exercise. – LH7 May 18 '15 at 18:16
  • 3
    Are you trying to apply style in the console output or you are trying to use it with swing or JSP? – Prabhakaran May 18 '15 at 18:16
  • 1
    @Hurix That's not going to work in general. For instance, in my eclipse console it just prints out garbage characters. – azurefrog May 18 '15 at 18:17
  • 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. – LH7 May 18 '15 at 18:19
  • yes, I need it to be shown in the console output – LH7 May 18 '15 at 18:20

2 Answers2

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.

Majora320
  • 1,321
  • 1
  • 13
  • 33
-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();
}
}
kamal
  • 195
  • 2
  • 9