This is a discussion on newbie question in java within the Java Programming forums, part of the Software Development category; Yeah. I can do any number with the fixed code above. I'll see what I can do. Thanks for ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
|
#11
| |||
| |||
| Yeah. I can do any number with the fixed code above. I'll see what I can do. Thanks for all the help/replies guys.this community brings out me a lot. |
|
#12
| |||
| |||
| Take a look at this link http://java.sun.com/docs/books/tuto...lts/arrays.html
__________________ cheers Aman |
|
#13
| |||
| |||
| I don't know if I did it the long way or whatever but I got it to work. Code: 1.
import java.io.*;
2.
import javax.swing.*;
3.
4.
class ArrT
5.
{
6.
7.
public static void main (String[] args) throws IOException {
8.
String inData;
9.
int[] anArray;
10.
11.
anArray = new int[20];
12.
13.
anArray[0] = 0;
14.
anArray[1] = 0;
15.
anArray[2] = 0;
16.
anArray[3] = 0;
17.
anArray[4] = 0;
18.
anArray[5] = 0;
19.
anArray[6] = 0;
20.
anArray[7] = 0;
21.
anArray[8] = 0;
22.
anArray[9] = 0;
23.
anArray[10] = 0;
24.
anArray[11] = 0;
25.
anArray[12] = 0;
26.
anArray[13] = 0;
27.
anArray[14] = 0;
28.
anArray[15] = 0;
29.
anArray[16] = 0;
30.
anArray[17] = 0;
31.
anArray[18] = 0;
32.
anArray[19] = 0;
33.
34.
inData = JOptionPane.showInputDialog (null, "Enter an Integer Value.") ;
35.
anArray[0] = Integer.parseInt ( inData); // convert inData to int
36.
37.
inData = JOptionPane.showInputDialog (null, "Enter another Integer Value.");
38.
anArray[1] = Integer.parseInt ( inData);
39.
40.
inData = JOptionPane.showInputDialog (null, "Enter another Integer Value.");
41.
anArray[2] = Integer.parseInt ( inData);
42.
inData = JOptionPane.showInputDialog (null, "Enter another Integer Value.");
43.
anArray[3] = Integer.parseInt ( inData);
44.
inData = JOptionPane.showInputDialog (null, "Enter another Integer Value.");
45.
anArray[4] = Integer.parseInt ( inData);
46.
inData = JOptionPane.showInputDialog (null, "Enter another Integer Value.");
47.
anArray[5] = Integer.parseInt ( inData);
48.
inData = JOptionPane.showInputDialog (null, "Enter another Integer Value.");
49.
anArray[6] = Integer.parseInt ( inData);
50.
inData = JOptionPane.showInputDialog (null, "Enter another Integer Value.");
51.
anArray[7] = Integer.parseInt ( inData);
52.
inData = JOptionPane.showInputDialog (null, "Enter another Integer Value.");
53.
anArray[8] = Integer.parseInt ( inData);
54.
inData = JOptionPane.showInputDialog (null, "Enter another Integer Value.");
55.
anArray[9] = Integer.parseInt ( inData);
56.
inData = JOptionPane.showInputDialog (null, "Enter another Integer Value.");
57.
anArray[10] = Integer.parseInt ( inData);
58.
inData = JOptionPane.showInputDialog (null, "Enter another Integer Value.");
59.
anArray[11] = Integer.parseInt ( inData);
60.
inData = JOptionPane.showInputDialog (null, "YOUSUCK! ENTER ANOHTER ONE.");
61.
anArray[12] = Integer.parseInt ( inData);
62.
inData = JOptionPane.showInputDialog (null, "Enter another Integer Value.");
63.
anArray[13] = Integer.parseInt ( inData);
64.
inData = JOptionPane.showInputDialog (null, "Enter another Integer Value.");
65.
anArray[14] = Integer.parseInt ( inData);
66.
inData = JOptionPane.showInputDialog (null, "This isn't over...");
67.
anArray[15] = Integer.parseInt ( inData);
68.
inData = JOptionPane.showInputDialog (null, "Enter another Integer Value.");
69.
anArray[16] = Integer.parseInt ( inData);
70.
inData = JOptionPane.showInputDialog (null, "Suck it blue!");
71.
anArray[17] = Integer.parseInt ( inData);
72.
inData = JOptionPane.showInputDialog (null, "Enter another Integer Value.");
73.
anArray[18] = Integer.parseInt ( inData);
74.
inData = JOptionPane.showInputDialog (null, "Enter another Integer Value.");
75.
anArray[19] = Integer.parseInt ( inData);
76.
77.
78.
int sum = anArray[0] + anArray[1] + anArray[2] + anArray[3] + anArray[4] + anArray[5] + anArray[6]
79.
+ anArray[7] + anArray[8] + anArray[9] + anArray[10] + anArray[11] + anArray[12] + anArray[13] +
80.
anArray[14] + anArray[15] + anArray[16] +anArray[17] + anArray[18] + anArray[19];
81.
int avg = sum/20;
82.
83.
System.out.println ("Sum of your sorry list of numbers is:" +sum);
84.
System.out.println ("The average is:" +avg);
85.
86.
System.out.println ("Good-bye for now, suckahfish!"); //always executed
87.
}
88.
89.
} Edit: I did have a question though. Because I'm having the user input their own value for each of the 20 numbers does it matter that I initialized each of the arrays at 0? Any information here is appreciated. Thanks for keeping up with me. |
|
#14
| |||
| |||
| Do Code: 1.
for(int i =0;i < anArray.length;i++ ) {
2.
System.out.println(anArray[i]);
3.
} before that string of anArray[i] = 0; to find out for yourself what values the array locations are initialized to.
__________________ cheers Aman |
|
#15
| |||
| |||
| Java is a programming language originally developed by Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities. ________________ promotional gifts Body Kits |
|
#16
| |||
| |||
| I'm sorry dude....i cant help you right away.... let me learn the best and i will help you then... ________________ hotel manhattan beach Bacca di Acai Berry Fruit Berries Cosmetic Surgeons UK Antivirus Products |
|
#17
| |||
| |||
| well java is a thing which require lots of practice |
|
#18
| |||
| |||
| Quote:
Your coding shows some error. while initializing the variable. Thanks ![]() Last edited by arjkhanna : 12-02-2009 at 11:32 PM. |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Hi Newbie here! | shifanyroma | Introductions | 2 | 08-14-2009 09:43 PM |
| newbie | pramod | Introductions | 2 | 07-08-2009 11:00 PM |
| Newbie here :) | angel_dust | Introductions | 3 | 07-05-2009 02:13 AM |
| Newbie! | taramichael | Introductions | 2 | 07-05-2009 01:22 AM |
Our Partners |