How to print an String variable as italicized text

瘦欲@ 提交于 2019-12-09 03:38:32

问题


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.


回答1:


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.




回答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();
}
}


来源:https://stackoverflow.com/questions/30310147/how-to-print-an-string-variable-as-italicized-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!