简体   繁体   English

如何在java中字符串或使用教科书样式数学

[英]How to string or work with textbook style math in java

I want to string math as it is in textbook using java. 我想在使用java的教科书中使用数学字符串。 Please help me with the best option to do this. 请帮助我做到这一点的最佳选择。 The code is just for the idea. 代码只是为了这个想法。 Thanks 谢谢

package app1;
import java.util.Scanner;
public class Tasnim {
    public static void main (String[] args){

double a,v=4,u=0,t=7;
    a=(v-u)/t;
        System.out.println("       "+"v - u");
        System.out.println("a = —————————");
        System.out.println("         t");
        System.out.println("   ");
        System.out.println("     "+v+" - "+u);
        System.out.println("a = —————————");
        System.out.println("        "+t);
        System.out.println("   ");
        System.out.println("        "+(v-u));
        System.out.println("a = —————————");
        System.out.println("        "+t);
        System.out.println("   ");
        System.out.printf("a =%9.4f\n",a);
        System.out.println("   ");
    }
}

Here i use 3 print method for a single line output. 这里我使用3种打印方法进行单行输出。 I also want to use mathematical symbol as '÷' and '×' etc. Any site or link or any idea where i can find the solution. 我也想用数学符号作为'÷'和'×'等。任何网站或链接或任何我能找到解决方案的想法。

/* Output example.
run:
       v - u
a = —————————
         t

     4.0 - 0.0
a = —————————
        7.0

        4.0
a = —————————
        7.0

a =   0.5714  */

Without external libs you hardly be able to avoid line by line printing, but can make it less concatenative. 没有外部库,您几乎无法避免逐行打印,但可以减少连接。 String.format or System.out.printf have a lot of nice formatting abilities which can help in simple cases ( java.util.Formatter ). String.formatSystem.out.printf有很多很好的格式化功能,在简单的情况下( java.util.Formatter )可以提供帮助。 There are also very skilled formatters for numbers in Java API. Java API中还有非常熟练的数字格式化程序。

For special symbols try to find the proper code page . 对于特殊符号,请尝试查找正确的code page Here are list of symbols and supported encoding list . 以下是符号列表支持的编码列表 Have no precise answer for the dvision sign, but the general idea is to use \\u\u003c/code> characters: 对于dvision标志没有确切的答案,但一般的想法是使用\\u\u003c/code>字符:

char c = '\u0025';
String s = new String(new byte[]{(byte) c}, Charset.forName("Cp850"));
System.out.printf("%c", c);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM