math equations in java

J

Jeremy Watts

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
 
A

Andrew Thompson

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.
 
W

Wojtek

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/
 
R

RedGrittyBrick

Jeremy said:
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
 
M

Marcus

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.
 
W

Wojtek

Lew wrote :
???

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.
 
L

Lew

Wojtek said:
Jeremy Watts wrote :
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.)
 
J

Jeremy Watts

bugbear said:
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
 
R

RedGrittyBrick

Jeremy said:
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");
 
J

Jeremy Watts

RedGrittyBrick said:
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
 
J

Jeremy Watts

Jeremy Watts said:
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
 
V

Vivien Barousse

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
 
A

Andrew Thompson

On May 25, 2:33 am, RedGrittyBrick <[email protected]>
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. ;-)
 
J

Jeremy Watts

RedGrittyBrick said:
Jeremy said:
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
 
A

Andrew Thompson

Jeremy Watts said:
..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).
 
A

Andrew Thompson

On May 25, 2:33=A0am, RedGrittyBrick <[email protected]>
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top