|
-
September 25th, 2005, 03:07 PM
#1
Simple Addition Progs
Hi I'm in an introductory Java course with a bad professor and I'm trying to get a hang of these basic concepts for an assignment using my notes and book, but im having lots of trouble compiling these things. If someone could quickly type out what a couple of these programs would look like, I could probably figure out the rest. Thanks so much.
"Write a program that reads two numbers, let's say num1 and num2, each time using JOptionPane.showInputDialog, Then use, for instance,
int value = Integer.parseInt(num1)
to convert each number to an int. Then add them and print the results."
Thats the most basic I think, but I keep getting errors like cannot resolve symbol.
This next one seems much more difficult and I'm not sure where to begin:
"Write a program that reads a 4-digit int, for instance, 3612, call it number. The program should separate the first two digits from the last two, and then add them. Thus in our example the program would assign 36 to a variable, let's say firstOne, and then assign 12 to a second variable, let's say secondOne. Finally, it would add the sum of firstOne and secondOne (here, 36 + 12, or 48) and assign it to a third variable, let's say sum.
The output of your program should show the 4-digit integer read, the integer formed from the first two digits, the integer formed from the last two and then their sum. Hint: Use the %(mod) and /(intger division).
Use JOptionPane.showInputDialog to read your data and assign the input to the string number. Then use
int value = Integer.parseInt(number)
to convert number to an int."
If I can get these basics I feel like I could figure out the rest, but the info I have is really not helping, and I have never programmed before. Thanks again.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|