java 如何将字符串变量打印为斜体文本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30310147/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to print an String variable as italicized text
提问by LH7
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 italictext.
我需要将变量上的值myName
打印为斜体文本。
回答by Majora320
Try:
尝试:
System.out.println("3[3mText goes here3[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
.
如果您的控制台支持,它将输出斜体文本。您可以使用[1m
粗体等。尝试使用[
n的不同值m
。
回答by kamal
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();
}
}