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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 16:52:56  来源:igfitidea点击:

How to print an String variable as italicized text

javaitalicstext-styling

提问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 myNameto 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 [1mfor 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();
}
}