Help With errors. Please.
I need help compiling my code in Java. I have a couple errors. Thanks for the help.
My code:
Code :
31 public class WeekTemp {
32
33 public static void main(String[] args) {
34 char[] ref = createArray();
35
36
37
38 System.out.println("Enter a integer between 1 and 52 to indicate the week of the year: ");
39 displayArray(ref);
40
41 int[] counts = countLetters(chars);
42
43 System.out.println();
44 System.out.println("The 10 reference values for the week are: ");
45 displayCounts(counts);
46
47
48 public static char[] createArray() {
49
50 char[] ref = new char[52];
51
52 for (int i = 0; i < chars.length; i++)
53 chars[i] = Random
54
55 public class WeekTemp {
56
57 public static void main(String[] args) {
58
59 // declares an array of integers
60
61 int[] anArray;
62
63 // allocates memory for 10 integers
64
65 anArray = new int[10];
66
67 // initialize first element
68
69 anArray[0] = 100;
70
71 // initialize second element
72
73 anArray[1] = 200;
74
75 // etc.
76
77 anArray[2] = 300;
78 anArray[3] = 400;
79 anArray[4] = 500;
80 anArray[5] = 600;
81 anArray[6] = 700;
82 anArray[7] = 800;
83 anArray[8] = 900;
84 anArray[9] = 1000;
85
86 System.out.println("Reference value 0: "
87 + anArray[0]);
88 System.out.println("Reference value 1: "
89 + anArray[1]);
90 System.out.println("Reference value 2: "
91 + anArray[2]);
92 System.out.println("Reference value 3: "
93 + anArray[3]);
94 System.out.println("Reference value 4: "
95 + anArray[4]);
96 System.out.println("Reference value 5: "
97 + anArray[5]);
98 System.out.println("Reference value 6: "
99 + anArray[6]);
100 System.out.println("Reference value 7: "
101 + anArray[7]);
102 System.out.println("Reference value 8: "
103 + anArray[8]);
104 System.out.println("Reference value 9: "
105 + anArray[9]);
106 }
107 }
108
109 public static double rms(double[] nums){
110 double ms = 0;
111 for (int i = 0; i < nums.length; i++)
112 ms += nums[i] * nums[i];
113 ms /= nums.length;
114 return Math.sqrt(ms);
115 }
116
117 public static void main(String[] args){
118 double[] nums = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0};
119 System.out.println("The 5 RMS deviations are: + rms(nums)");
120 }
121 }
122 }
Errors:
Code :
% javac WeekTemp.java
WeekTemp.java:48: illegal start of expression
public static char[] createArray() {
^
WeekTemp.java:55: ';' expected
public class WeekTemp {
^
WeekTemp.java:109: illegal start of expression
public static double rms(double[] nums){
^
WeekTemp.java:121: ';' expected
}
^
4 errors
%
Re: Help With errors. Please.
Well, what are you trying to do in the first place? It'd be a lot more helpful if we knew the reason behind what the code actually does.
EDIT: And well, line 53 just sets each element to "Random", I'm not sure if that got cut off while pasting, but, that definitely doesn't make sense.
Re: Help With errors. Please.
The arrays obs[] and ref[] are each 10 elements long, with obs[] representing the 10 different readings taken on a given day in the plant. Now, the values of the 10 elements in obs[] change every day of the five-day week but for a given week, the ref[] values are the same. These can be thought of fixed values to be adhered to for a whole week, but the fixed values are different for different weeks. The goal is to find the total deviation for a given week.