How to type π (pi) in Java?

后端 未结 3 1064
深忆病人
深忆病人 2020-12-20 14:53

Is there a character within the Math API that allows for representing the character π?

3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-20 15:09

    If you want to write this to a file you can achieve it through Unicodes, below is an example of how,

    import java.io.*;
    public class Test {
    
        public static void main(String[] args) throws Exception{
            BufferedWriter out = 
                        new BufferedWriter(new OutputStreamWriter(
                              new FileOutputStream("out.txt"),"UTF8"));     
    
        out.write("alpha = \u03B1, beta = \u03B2 ,pi = \u03C0");
        out.flush();
        out.close();
    }
    }
    

    out put : alpha = α, beta = β ,pi = π

提交回复
热议问题