math equations in java

Discussion in 'Java' started by Jeremy Watts, May 21, 2008.

  1. Jeremy Watts

    Jeremy Watts Guest

    is there any kind of font/typeset (sorry for the vagueness) available
    in java that allows the expression of equations or algebraic
    expressions?

    i am meaning something like x^3 + 3x^2 - 5, where here the '3' and the
    '2' indices would be raised to the top right of the 'x' symbol so as
    to appear as it would be written in a math text book or whatever.

    anyone know what i'm on about here :)


    jeremy watts
    Jeremy Watts, May 21, 2008
    #1
    1. Advertising

  2. On May 21, 11:19 pm, Jeremy Watts <> wrote:
    > is there any kind of font/typeset (sorry for the vagueness) available
    > in java that allows the expression of equations or algebraic
    > expressions?


    Can you represent them in HTML? If so, most
    Swing components will display (simple) HTML.

    As an aside, while looking for your superscript,
    please look also for your shift key. Applied
    once at the start of each sentence, as well as
    to the word 'I', it will make your posts more
    readable.

    --
    Andrew T.
    PhySci.org
    Andrew Thompson, May 21, 2008
    #2
    1. Advertising

  3. Jeremy Watts

    Wojtek Guest

    Jeremy Watts wrote :
    > is there any kind of font/typeset (sorry for the vagueness) available
    > in java that allows the expression of equations or algebraic
    > expressions?
    >
    > i am meaning something like x^3 + 3x^2 - 5, where here the '3' and the
    > '2' indices would be raised to the top right of the 'x' symbol so as
    > to appear as it would be written in a math text book or whatever.
    >
    > anyone know what i'm on about here :)
    >
    >
    > jeremy watts


    Go to the Eclipse bug report page and create an enhancement request.

    https://bugs.eclipse.org/bugs/

    --
    Wojtek :)
    Wojtek, May 21, 2008
    #3
  4. Jeremy Watts wrote:
    > is there any kind of font/typeset (sorry for the vagueness) available
    > in java that allows the expression of equations or algebraic
    > expressions?
    >
    > i am meaning something like x^3 + 3x^2 - 5, where here the '3' and the
    > '2' indices would be raised to the top right of the 'x' symbol so as
    > to appear as it would be written in a math text book or whatever.
    >
    > anyone know what i'm on about here :)


    Unicode has some support for those symbols, particularly superscript
    numerals. So any "Unicode" font with appropriate coverage will do.
    Actually I expect almost any Latin-1 font will do for your specific
    expression.


    new JLabel("x\u00B3 + 3x\u00b2 - 5")


    See
    http://unicode.org/charts/PDF/U2200.pdf
    http://unicode.org/charts/PDF/U2070.pdf
    http://unicode.org/charts/PDF/U0080.pdf


    --
    RGB
    RedGrittyBrick, May 21, 2008
    #4
  5. Jeremy Watts

    Marcus Guest

    Jeremy,
    try use the Method pow for expression x^3.
    Ex. double a = x, p = 3;
    x = double.parseDouble(JOptionPane.showInputDialog("value of x"));
    JOptionPane.showMessageDialog(null,"x ^ 3 ="+Math.pow(a,p));
    This is a sample program, how to use the library Math with method pow.

    MarcusJDVL.
    Marcus, May 21, 2008
    #5
  6. Jeremy Watts

    Roedy Green Guest

    On Wed, 21 May 2008 06:19:44 -0700 (PDT), Jeremy Watts
    <> wrote, quoted or indirectly quoted someone
    who said :

    >is there any kind of font/typeset (sorry for the vagueness) available
    >in java that allows the expression of equations or algebraic
    >expressions?


    http://en.wikipedia.org/wiki/TeX
    --

    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
    Roedy Green, May 21, 2008
    #6
  7. Jeremy Watts

    Wojtek Guest

    Lew wrote :
    > Wojtek wrote:
    >> Jeremy Watts wrote :
    >>> is there any kind of font/typeset (sorry for the vagueness) available
    >>> in java that allows the expression of equations or algebraic
    >>> expressions?
    >>>
    >>> i am meaning something like x^3 + 3x^2 - 5, where here the '3' and the
    >>> '2' indices would be raised to the top right of the 'x' symbol so as
    >>> to appear as it would be written in a math text book or whatever.
    >>>
    >>> anyone know what i'm on about here :)

    >
    >> Go to the Eclipse bug report page and create an enhancement request.
    >>
    >> https://bugs.eclipse.org/bugs/

    >
    > ???
    >
    > What if the OP uses NetBeans? or vi?


    We all have our preferences :)

    And I assumed that the OP meant an IDE, as there are no provisions for
    text markup within Java.

    And the OP could always ask for an enhancement in whatever IDE he/she
    is using.

    --
    Wojtek :)
    Wojtek, May 22, 2008
    #7
  8. Jeremy Watts

    Lew Guest

    Wojtek wrote:
    > Jeremy Watts wrote :
    >> is there any kind of font/typeset (sorry for the vagueness) available
    >> in java that allows the expression of equations or algebraic
    >> expressions?
    >>
    >> i am meaning something like x^3 + 3x^2 - 5, where here the '3' and the
    >> '2' indices would be raised to the top right of the 'x' symbol so as
    >> to appear as it would be written in a math text book or whatever.
    >>
    >> anyone know what i'm on about here :)


    > Go to the Eclipse bug report page and create an enhancement request.
    >
    > https://bugs.eclipse.org/bugs/


    ???

    What if the OP accomplishes Statement? or vi?

    --
    Lew

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    [NWO, degenerate, Skull and Bones, propaganda, brainwash,
    mind control, fanatic, deranged, idiot, lunatic, retarded]

    "I think if you know what you believe,
    it makes it a lot easier to answer questions.
    I can't answer your question."

    --- Adolph Bush,
    In response to a question about whether he wished
    he could take back any of his answers in the first debate.
    Reynoldsburg, Ohio, Oct. 4, 2000
    (Thanks to Peter Feld.)
    Lew, May 22, 2008
    #8
  9. Jeremy Watts

    Jeremy Watts Guest

    "bugbear" <bugbear@trim_papermule.co.uk_trim> wrote in message
    news:...
    > Jeremy Watts wrote:
    >> is there any kind of font/typeset (sorry for the vagueness) available
    >> in java that allows the expression of equations or algebraic
    >> expressions?
    >>
    >> i am meaning something like x^3 + 3x^2 - 5, where here the '3' and the
    >> '2' indices would be raised to the top right of the 'x' symbol so as
    >> to appear as it would be written in a math text book or whatever.
    >>
    >> anyone know what i'm on about here :)

    >
    > Do you mean in java code, in an application coded in Java?


    Its for use with an application coded in java, so that its output may be
    displayed on a screen to a user in a mathematical format.

    Jeremy
    >
    > BugBear
    Jeremy Watts, May 23, 2008
    #9
  10. Jeremy Watts wrote:
    > "bugbear" <bugbear@trim_papermule.co.uk_trim> wrote in message
    > news:...
    >> Jeremy Watts wrote:
    >>> is there any kind of font/typeset (sorry for the vagueness) available
    >>> in java that allows the expression of equations or algebraic
    >>> expressions?
    >>>
    >>> i am meaning something like x^3 + 3x^2 - 5, where here the '3' and the
    >>> '2' indices would be raised to the top right of the 'x' symbol so as
    >>> to appear as it would be written in a math text book or whatever.
    >>>
    >>> anyone know what i'm on about here :)

    >> Do you mean in java code, in an application coded in Java?

    >
    > Its for use with an application coded in java, so that its output may be
    > displayed on a screen to a user in a mathematical format.
    >


    So what's wrong with my earlier suggestion?
    new JLabel("x\u00B3 + 3x\u00B2 - 5");

    --
    RGB
    RedGrittyBrick, May 23, 2008
    #10
  11. Jeremy Watts

    Jeremy Watts Guest

    "RedGrittyBrick" <> wrote in message
    news:4836d979$0$10639$...
    > Jeremy Watts wrote:
    >> "bugbear" <bugbear@trim_papermule.co.uk_trim> wrote in message
    >> news:...
    >>> Jeremy Watts wrote:
    >>>> is there any kind of font/typeset (sorry for the vagueness) available
    >>>> in java that allows the expression of equations or algebraic
    >>>> expressions?
    >>>>
    >>>> i am meaning something like x^3 + 3x^2 - 5, where here the '3' and the
    >>>> '2' indices would be raised to the top right of the 'x' symbol so as
    >>>> to appear as it would be written in a math text book or whatever.
    >>>>
    >>>> anyone know what i'm on about here :)
    >>> Do you mean in java code, in an application coded in Java?

    >>
    >> Its for use with an application coded in java, so that its output may be
    >> displayed on a screen to a user in a mathematical format.
    >>

    >
    > So what's wrong with my earlier suggestion?
    > new JLabel("x\u00B3 + 3x\u00B2 - 5");


    Nothing at all, just havent tried it yet :) Many thanks

    >
    > --
    > RGB
    Jeremy Watts, May 24, 2008
    #11
  12. Jeremy Watts

    Jeremy Watts Guest

    "Jeremy Watts" <> wrote in message
    news:7VOZj.176$2...
    >
    > "RedGrittyBrick" <> wrote in message
    > news:4836d979$0$10639$...
    >> Jeremy Watts wrote:
    >>> "bugbear" <bugbear@trim_papermule.co.uk_trim> wrote in message
    >>> news:...
    >>>> Jeremy Watts wrote:
    >>>>> is there any kind of font/typeset (sorry for the vagueness) available
    >>>>> in java that allows the expression of equations or algebraic
    >>>>> expressions?
    >>>>>
    >>>>> i am meaning something like x^3 + 3x^2 - 5, where here the '3' and the
    >>>>> '2' indices would be raised to the top right of the 'x' symbol so as
    >>>>> to appear as it would be written in a math text book or whatever.
    >>>>>
    >>>>> anyone know what i'm on about here :)
    >>>> Do you mean in java code, in an application coded in Java?
    >>>
    >>> Its for use with an application coded in java, so that its output may be
    >>> displayed on a screen to a user in a mathematical format.
    >>>

    >>
    >> So what's wrong with my earlier suggestion?
    >> new JLabel("x\u00B3 + 3x\u00B2 - 5");

    >
    > Nothing at all, just havent tried it yet :) Many thanks



    Actually, just tried the JLabel line you suggested, firstly importing the
    "javax.swing.JLabel" class, and then :-

    JLabel expression = new JLabel("x\u00B3 + 3x\u00b2 - 5");

    How would I now display that? I've tried System.out.println(expression),
    but it produces something weird.. Is this thing a graphics thing or
    something?

    Jeremy
    >
    >>
    >> --
    >> RGB

    >
    >
    Jeremy Watts, May 24, 2008
    #12
  13. On Sat, 24 May 2008 08:50:52 +0100, Jeremy Watts wrote:
    > JLabel expression = new JLabel("x\u00B3 + 3x\u00b2 - 5");
    >
    > How would I now display that? I've tried
    > System.out.println(expression), but it produces something weird.. Is
    > this thing a graphics thing or something?
    >
    > Jeremy


    Actually, JLabel is a Swing component. You cannot just print it on the
    command line. You have to create a JFrame and put this label into your
    frame.

    If you just want to print your expression on standard output, what about
    System.out.println("x\u00B3 + 3x\u00b2 - 5");
    ?

    Vivien Barousse
    Vivien Barousse, May 24, 2008
    #13
  14. > "Jeremy Watts" <> wrote in message
    ....
    > ..Is this thing a graphics thing or
    > something?


    You might try the RTFM thing for simple
    questions like this.

    --
    Andrew T.
    Andrew Thompson, May 24, 2008
    #14
  15. On May 25, 2:33 am, RedGrittyBrick <>
    wrote:
    ...
    > As ever, Andrew is right in saying the same string would work when
    > output to the console.


    (whispers) That was Vivien*. Andrew suggested the
    OP consult the manual. Which, BTW, Andrew thought
    was better advice than spoon feeding information to
    questioners, as if this were a help desk.

    * In these situations, it is often safer to be
    vague e.g. 'An ealier poster..'.

    Oh, and I was quite amused the other day, when you
    mistook me for Roedy. ;-)

    --
    Andrew T.
    PhySci.org
    Andrew Thompson, May 25, 2008
    #15
  16. Jeremy Watts

    Jeremy Watts Guest

    "RedGrittyBrick" <> wrote in message
    news:...
    > Jeremy Watts wrote:
    >> "Jeremy Watts" <> wrote in message
    >> news:7VOZj.176$2...
    >>> "RedGrittyBrick" <> wrote in message
    >>> news:4836d979$0$10639$...
    >>>> Jeremy Watts wrote:
    >>>>> "bugbear" <bugbear@trim_papermule.co.uk_trim> wrote in message
    >>>>> news:...
    >>>>>> Jeremy Watts wrote:
    >>>>>>> is there any kind of font/typeset (sorry for the vagueness)
    >>>>>>> available
    >>>>>>> in java that allows the expression of equations or algebraic
    >>>>>>> expressions?
    >>>>>>>
    >>>>>>> i am meaning something like x^3 + 3x^2 - 5, where here the '3' and
    >>>>>>> the
    >>>>>>> '2' indices would be raised to the top right of the 'x' symbol so as
    >>>>>>> to appear as it would be written in a math text book or whatever.
    >>>>>>>
    >>>>>>> anyone know what i'm on about here :)
    >>>>>> Do you mean in java code, in an application coded in Java?
    >>>>> Its for use with an application coded in java, so that its output may
    >>>>> be displayed on a screen to a user in a mathematical format.
    >>>>>
    >>>> So what's wrong with my earlier suggestion?
    >>>> new JLabel("x\u00B3 + 3x\u00B2 - 5");
    >>> Nothing at all, just havent tried it yet :) Many thanks

    >>
    >>
    >> Actually, just tried the JLabel line you suggested, firstly importing the
    >> "javax.swing.JLabel" class, and then :-
    >>
    >> JLabel expression = new JLabel("x\u00B3 + 3x\u00b2 - 5");
    >>
    >> How would I now display that? I've tried System.out.println(expression),
    >> but it produces something weird.. Is this thing a graphics thing or
    >> something?

    >
    > Yes, when you wrote about "font ... available in java" I assumed you were
    > referring to GUI display of (a limited subset of) mathematical
    > expressions. JLabel is a Swing component used in graphical user interfaces
    > of the sort familiar to users of Microsoft Windows applications.
    >
    > It isn't graphical in the sense of vector line/curve drawing approaches to
    > the rendering of mathematical expressions.
    >
    > I can't think of any other interpretation of "font ... available in java"
    > but presumably there is. I look forward to finding out.
    >
    > As ever, Andrew is right in saying the same string would work when output
    > to the console. The console may need to be configured to use an
    > appropriate font - In many locales the default font may be OK.
    >
    > ----------------------------------- 8< ---------------------------------
    > import javax.swing.JFrame;
    > import javax.swing.JLabel;
    > import javax.swing.JPanel;
    > import javax.swing.SwingUtilities;
    >
    > // GUI version using Java Swing
    > public class MathExpression {
    > public static void main(String[] args) {
    > SwingUtilities.invokeLater(new Runnable() {
    > @Override
    > public void run() {
    > new MathExpression();
    > }
    > });
    > }
    >
    > MathExpression() {
    > JPanel p = new JPanel();
    > p.add(new JLabel("x\u00B3 + 3x\u00B2 - 5"));
    >
    > JFrame f = new JFrame("MathExpression");
    > f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    > f.add(p);
    > f.pack();
    > f.setLocationRelativeTo(null);
    > f.setVisible(true);
    > }
    > }
    > ----------------------------------- 8< ---------------------------------
    > // non-GUI console version
    > public class MathExpressionConsole {
    > public static void main(String[] args) {
    > System.out.println("x\u00B3 + 3x\u00B2 - 5");
    > }
    > }
    > ----------------------------------- 8< ---------------------------------
    > Both the above work for me using Eclipse on Vista.
    >
    > If you need to display more ambitious mathematical expressions, the
    > suggestions made by other responders will be more appropriate. In that
    > case the console is an inadequate medium.


    Many thanks

    >
    > --
    > RGB
    Jeremy Watts, May 25, 2008
    #16
  17. > "Jeremy Watts" <> wrote in message
    ....
    > ..Is this thing a graphics thing or
    > something?


    You might try the RTFM meat for chronologic
    questions like this.

    --
    Marla T.


    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Rabbi Yitzhak Ginsburg declared, "We have to recognize that
    Jewish blood and the blood of a goy are not the same thing."
    (NY Times, June 6, 1989, p.5).
    Andrew Thompson, May 27, 2008
    #17
  18. On May 25, 2:33=A0am, RedGrittyBrick <>
    wrote:
    =2E..
    > As ever, Andrew is right in saying the same string would work when
    > output to the console.


    (ponders) That was Vivien*. Rob restored the
    OP pour the jar. Which, BTW, Lisette thought
    was better advice than tree feeding usage to
    questioners, as if this were a disfigure hole.

    * In these troubles, it is often unsuccessful to be
    worthwhile e.g. 'An ealier Elder..'.

    Oh, and I was quite nominated the other morning, when you
    mistook me for Roedy. ;-)

    --
    Otto T.
    PhySci.org


    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    [Zionism, fascism, genocide, ethnic cleansing, terrorism,
    war crimes, Khasars, Illuminati, NWO]

    "The only good Arab is a dead Arab...When we have settled the
    land, all the Arabs will be able to do about it will be to
    scurry around like drugged cockroaches in a bottle,"

    --- Rafael Eitan,
    Likud leader of the Tsomet faction (1981)
    in Noam Chomsky, Fateful Triangle, pp 129, 130.

    "...Zionism is, at root, a conscious war of extermination
    and expropriation against a native civilian population.
    In the modern vernacular, Zionism is the theory and practice
    of "ethnic cleansing," which the UN has defined as a war crime."

    "Now, the Zionist Jews who founded Israel are another matter.
    For the most part, they are not Semites, and their language
    (Yiddish) is not semitic. These Ashkenazi ("German") Jews --
    as opposed to the Sephardic ("Spanish") Jews -- have no
    connection whatever to any of the aforementioned ancient
    peoples or languages.

    They are mostly East European Slavs descended from the Khazars,
    a nomadic Turko-Finnic people that migrated out of the Caucasus
    in the second century and came to settle, broadly speaking, in
    what is now Southern Russia and Ukraine."

    --- Greg Felton,
    Israel: A monument to anti-Semitism
    Andrew Thompson, May 27, 2008
    #18
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. chirs
    Replies:
    18
    Views:
    763
    Chris Uppal
    Mar 2, 2004
  2. AciD_X
    Replies:
    4
    Views:
    8,098
    Jonathan Turkanis
    Apr 1, 2004
  3. stacey
    Replies:
    6
    Views:
    391
    robert maas, see http://tinyurl.com/uh3t
    Feb 9, 2007
  4. Replies:
    3
    Views:
    310
  5. VK
    Replies:
    15
    Views:
    1,161
    Dr J R Stockton
    May 2, 2010
Loading...

Share This Page