Results 1 to 7 of 7
Thread: Help me please!!!!!!!!!!!!
- 01-27-2009, 05:22 AM #1
Member
- Join Date
- Jan 2008
- Posts
- 23
- Rep Power
- 0
Help me please!!!!!!!!!!!!
I need some help with this program:
Write a java program that prompts the user to enter five numbers. Calculate the average, the sum, and the product of these five numbers. Display the results in a format similar to this:
The sum is 12
The product is 44
The average is 34
Use Scanner for text input and System.out.println for the output.
This is the code I have so far. Can someone please help me?
import javax.swing.JOptionPane;
public class MathData1 {
public static void main(String[] args) {
JOptionPane.showInputDialog(null,
"Enter Integer 1",
"Input Dialog",
JOptionPane.QUESTION_MESSAGE);
JOptionPane.showInputDialog(null,
"Enter Integer 2",
"Input Dialog",
JOptionPane.QUESTION_MESSAGE);
JOptionPane.showInputDialog(null,
"Enter Integer 3",
"Input Dialog",
JOptionPane.QUESTION_MESSAGE);
JOptionPane.showInputDialog(null,
"Enter Integer 4",
"Input Dialog",
JOptionPane.QUESTION_MESSAGE);
JOptionPane.showInputDialog(null,
"Enter Integer 5",
"Input Dialog",
JOptionPane.QUESTION_MESSAGE);
// Convert string to int
int intValue = Integer.parseInt(intString);
//Obtain Sum
sum = "int 1" + "int 2" + "int 3" + "int 4" + "int 5";
JOptionPane.showMessageDialog(null,
"Sum"
JOptionPane.INFORMATION_MESSAGE);
}
}
- 01-27-2009, 05:30 AM #2
the question asks for Scanner class not JOption.
here's how to use it.
Java Code:Scanner input = new Scanner(System.in); int n = input.nextInt();
Last edited by angryboy; 01-27-2009 at 06:04 AM. Reason: useless stuff removed
USE CODE TAGS--> [CODE]...[/CODE]
Get NotePad++ (free)
- 01-27-2009, 05:34 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 23
And also please use code tags posting again. Un-formatted codes are really hard to read.
- 01-27-2009, 05:39 AM #4
Member
- Join Date
- Jan 2008
- Posts
- 23
- Rep Power
- 0
Code Tags????????
I dont understand? Are code tags (comments) for each section? or what ????
I am new to this ( 2 weeks old)!!!!!!!!!!
Thanks
Chitwood
- 01-27-2009, 05:56 AM #5
Member
- Join Date
- Jan 2008
- Posts
- 23
- Rep Power
- 0
Is this a little better?
import javax.swing.JOptionPane;
public class MathData1 {
public static void main(String[] args) {
//Input 5 Numbers
JOptionPane.showInputDialog(null,
"Enter Integer 1",
"Input Dialog",
JOptionPane.QUESTION_MESSAGE);
JOptionPane.showInputDialog(null,
"Enter Integer 2",
"Input Dialog",
JOptionPane.QUESTION_MESSAGE);
JOptionPane.showInputDialog(null,
"Enter Integer 3",
"Input Dialog",
JOptionPane.QUESTION_MESSAGE);
JOptionPane.showInputDialog(null,
"Enter Integer 4",
"Input Dialog",
JOptionPane.QUESTION_MESSAGE);
JOptionPane.showInputDialog(null,
"Enter Integer 5",
"Input Dialog",
JOptionPane.QUESTION_MESSAGE);
int 1int = Integer.parseInt(1String);
int 2int = Integer.parseInt(2String);
int 3int = Integer.parseInt(3String);
int 4int = Integer.parseInt(4String);
int 5int = Integer.parseInt(5String);
// Convert string to int
int intValue = Integer.parseInt(intString);
//Obtain Sum
doublesum = "int 1" + "int 2" + "int 3" + "int 4" + "int 5";
JOptionPane.showMessageDialog(null,
"Sum")
JOptionPane.INFORMATION_MESSAGE;
}
}
- 01-27-2009, 05:58 AM #6
Code
wrap the code in code tags. like this:
XML Code:[CODE] codes here [/CODE]
Last edited by angryboy; 01-27-2009 at 07:31 AM.
USE CODE TAGS--> [CODE]...[/CODE]
Get NotePad++ (free)
- 01-27-2009, 07:10 AM #7
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 23
Bookmarks