Re: Simple Addition Progs
Quote:
Thats the most basic I think, but I keep getting errors like cannot resolve symbol.
Every class exists within a package (in other languages it's also called a namespace). For instance, the JOptionPane is located within the "javax.swing" package. So, to use the JOptionPane in your code you'll have a couple of choices:
1. Import all classes in the "javax.swing" package:
Code:
import javax.swing.*;
publc class YourClass
{
public void yourFunction()
{
// your JOptionPane here
JOptionPane pPane = new JOptionPane(...);
}
}
2. If you don't want to import all the classes in "javax.swing", but just the JOptionPane, then replace your import with this:
Code:
import javax.swing.JOptionPane;
3. You can also refer to the class with it's "full" name:
Code:
class YourClass
{
public void yourFunction()
{
javax.swing.JOptionPane pPane = new javax.swing.JOptionPane(...);
}
}
Hope this help you solve some of those "cannot resolve symbol" errors.
- petter
Re: Simple Addition Progs
That seems to be a good start, but I still have no idea how to assemble this thing. What I have so far looks like this:
import javax.swing.JOptionPane;
public class Prog1
{
public static void main(String {} asd)
{
I dont know how to incorporate the actual JOptionPane to get integers, add them, and print a sum. He showed us something that I copied directly like this:
char digit1 = '1';
char digit2 = '2';
int num1 = digit1;
int num2 = digit2;
int sum = num1 + num2;
not sure if thats actually useful here?
Re: Simple Addition Progs
http://java.sun.com/j2se/1.5.0/docs/api/
check the api documentation.................
Re: Simple Addition Progs
Using JOptionPane to get input is pretty simple:
Code:
String input = JOptionPane.showInputDialog("Enter a number");
int number = Integer.parseInt(input);
That's your input routine for reading in 1 number, plain and simple (I havn't worked with JOptionPane for quite a while so it may need some tweaking in terms of what parameters to pass).
As for separating the 4 digit number, you have to use a little math cleverness. If you mod(%) the number by 100, the result is the last two numbers, if you divide(/) a number by 100, you get the first two numbers.