Join 150,374 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,692 people online right now. Registration is fast and FREE... Join Now!
Hello to everyone..I have a problem while trying to fill a byte array.. Also I am not sure if what I need is a byte array. Excuse me for my english and thanx in advance
CODE
import java.io.*;
public class Filicite { public static byte a_raisiny; byte a_raisiny [] = {a, b, c, d, e, f, g, h, i, 1, -, 2, 3}; public static long m_gurnard (String Exercise, long sum) { if (Exercise.length!=759) break; Exercise = new FileInputStream(); int b; while ((b = Exercise.read()) != -1) { for (int i=0; i<13; i++) { if (b != a_raisiny[i]) break; else { int [] num = new int [13]; for (int i=0; i<13; i++) { num [i]=0; } for (int i=0; i<13; i++) { if (b = a_raisiny[i]) num[i]++; } } } } for (int i=0; i<13; i++) { if (num [i]<55 && num [i]>60) break; } Exercise.close(); int su=0; for (int j=0; Exercise.read<500; j++) { sum+=Character.getNumericValue((char)j); } long sum = su; return sum; } public static int m_subtilin (String Characters, int a []) { Characters = new InputStreamReader(); long x = Characters.length(); int [] a = new int [14]; a [0] = x; int n1 = 0; int n2 = 0; int n3 = 0; int n4 = 0; int n5 = 0; int n6 = 0; int n7 = 0; int n8 = 0; int n9 = 0; int n10 = 0; int n11 = 0; int n12 = 0; int n13 = 0; int c; while ((c = Characters.read()) != -1) { if (Characters.read() == a_raisiny[0]) n1++; if (Characters.read() == a_raisiny[1]) n2++; if (Characters.read() == a_raisiny[2]) n3++; if (Characters.read() == a_raisiny[3]) n4++; if (Characters.read() == a_raisiny[4]) n5++; if (Characters.read() == a_raisiny[5]) n6++; if (Characters.read() == a_raisiny[6]) n7++; if (Characters.read() == a_raisiny[7]) n8++; if (Characters.read() == a_raisiny[8]) n9++; if (Characters.read() == a_raisiny[9]) n10++; if (Characters.read() == a_raisiny[10]) n11++; if (Characters.read() == a_raisiny[11]) n12++; if (Characters.read() == a_raisiny[12]) n13++; } a [1] = n1; a [2] = n2; a [3] = n3; a [4] = n4; a [5] = n5; a [6] = n6; a [7] = n7; a [8] = n8; a [9] = n9; a [10] = n10; a [11] = n11; a [12] = n12; a [13] = n13; for (int j = 0; j<14; j++) { return a [j]; } Characters.close(); } }
error: Filicite.java:5: illegal start of expression byte a_raisiny [] = {a, b, c, d, e, f, g, h, i, 1, -, 2, 3}; ^ 1 error
Since you already have a variable declared as a_raisiny you can't declare a second variable with the same name, even if it's a different type. Also, you attempt to fill the array with undeclared variables. In your m_gurnard() method, you have a String declared as "Exercise" but later in the same method you attempt to make "Exercise" of type FileInputStream.
Just out of curiosity, what are you trying to do here?
This post has been edited by GWatt: 26 Jan, 2008 - 11:27 AM
I have to write a public class Filicite with two static methods m_gurnard and m_subtilin .The first one m_gurnard must accept a String. This string will contain the file of the name that will be created. This file must have - size: 759 bytes - list of allowable characters: byte[] a_raisiny = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', '1', '-', '2', '3'}. This list must be defined as static public attribute of Filicite with the name a_raisiny. The data of the file (the characters) must have almost the same times of appearence. The method m_gurnard must return a variable long which will contain the sum of the prices ASCII of 500 first characters. The method m_subtilin must accept a (String) which will contain the name of a file of characters. The file will be read from the memory and we will have to know (take) - size - number of appearence of every character contained in the array defined in the array a_raisiny.
The data must be returned as an array o integers from m_subtilin. This array in the first place (ex a[0]) will have the size of the file and in the rest the number of appearence of every character (ex. in second place the number of appearence of the first character) Sorry again for my english...
This post has been edited by yolanda_av: 26 Jan, 2008 - 11:44 AM
OK, now that i have a better handle on what you're doing, I can help you better.
When you declare a_raisiny, use the first declaration you had. When you fill it with characters, put single quotes around each element. eg: 'a'
I'm not going to tell you everything you need to do, but I will try to help you get your code to the compilation point. I'm not even looking for logical errors here.
m_gurnard() method:
You attempt to get the length of the String "Exercise" with the .length member. There is no .length member of the string class. There is a .length() though. The .length member is used most commonly by arrays.
Instead of trying to reassign the String "Exercise" to be of type FileInputStream (hereafeter referred to as FIS), create a new variable that's already of type FIS. If we look at the Java Doc, we see that FIS will accept a String as a parameter and will attempt to open a file with that name.
Later in the method you attempt to close the String "Exercise". You'll need to declare and use a different identifier of type FIS. Two lines after that you call .read but forgot about the '()' at te end of the method call.
m_subtilin() method: you have a string entitled "Characters" whih you attempt to change to type of InputStreamReader (ISR). Same thing as with "Exercise" in m_gurnard(). Create an ISR and use that in most of the places you have "Characters" right now
No, a_raisiny doesn't have to be of type char. type char is just a special type of integer. If you were to copy this segment of code into a class it would be perfectly legal:
CODE
char a = 'a' byte b_a = a; System.out.println(b_a);
It would give you the integer value of the character 'a'.
This post has been edited by GWatt: 26 Jan, 2008 - 12:43 PM
Well ok... But I need some help with your previous post..How can I create a variable of type FIS? Also I didn't understand how I declare the a_raisiny.I replaced these 2 lines public static byte a_raisiny; byte a_raisiny [] = {a, b, c, d, e, f, g, h, i, 1, -, 2, 3}; with this one public static byte a_raisiny [] = {a, b, c, d, e, f, g, h, i, 1, -, 2, 3}; and there is still the same error.If I put the characters into ' ' it appears to me many more errors...
FIS is simply the shorthand I used for FileInputStream. Every where I said FIS, replace that with FileInputStream. You create a varialbe of type FileInputStream like so: FileInputStream fis = new FileInputStream(/*something here*/);
declare your array like this: public static byte a_raisiny [] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', '1', '-', '2', '3'};
public class Filicite { public static byte a_raisiny [] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', '1', '-', '2', '3'}; public static long m_gurnard (String Exercise, long sum) { if (Exercise.length()!=759) break; FileInputStream fis = new FileInputStream(Exercise); int b; while ((b = fis.read()) != -1) { for (int i=0; i<13; i++) { if (b != a_raisiny[i]) break; else { int [] num = new int [13]; for (int i=0; i<13; i++) { num [i]=0; } for (int i=0; i<13; i++) { if (b = a_raisiny[i]) num[i]++; } } } } for (int i=0; i<13; i++) { if (num [i]<55 && num [i]>60) break; } fis.close(); int su=0; for (int j=0; Exercise.read()<500; j++) { sum+=Character.getNumericValue((char)j); } long sum = su; return sum; } public static int m_subtilin (String Characters, int a []) { InputStreamReader isr = new InputStreamReader(Characters); long x = isr.length(); int [] b = new int [14]; b [0] = int(x); int n1 = 0; int n2 = 0; int n3 = 0; int n4 = 0; int n5 = 0; int n6 = 0; int n7 = 0; int n8 = 0; int n9 = 0; int n10 = 0; int n11 = 0; int n12 = 0; int n13 = 0; int c; while ((c = isr.read()) != -1) { if (isr.read() == a_raisiny[0]) n1++; if (isr.read() == a_raisiny[1]) n2++; if (isr.read() == a_raisiny[2]) n3++; if (isr.read() == a_raisiny[3]) n4++; if (isr.read() == a_raisiny[4]) n5++; if (isr.read() == a_raisiny[5]) n6++; if (isr.read() == a_raisiny[6]) n7++; if (isr.read() == a_raisiny[7]) n8++; if (isr.read() == a_raisiny[8]) n9++; if (isr.read() == a_raisiny[9]) n10++; if (isr.read() == a_raisiny[10]) n11++; if (isr.read() == a_raisiny[11]) n12++; if (isr.read() == a_raisiny[12]) n13++; } b [1] = n1; b [2] = n2; b [3] = n3; b [4] = n4; b [5] = n5; b [6] = n6; b [7] = n7; b [8] = n8; b [9] = n9; b [10] = n10; b [11] = n11; b [12] = n12; b [13] = n13; for (int j = 0; j<14; j++) { return b [j]; } isr.close(); } }
Next time, could you please share the compiler error message. It's just easier to help if you do that.
Anyway, around line 38, you have a statement that reads b [0] = int(x); If you wanted to cast the value of x in that statement to an int, then the syntax is: b[0] = (int) x; You put the parens around the type to which you want to cast.
This doesn't seem to be the problem...When I correct this I get 10 new errors...
C:\Users\Yo\Documents\Filicite.java:6: break outside switch or loop if (Exercise.length()!=759) break; ^ C:\Users\Yo\Documents\Filicite.java:14: i is already defined in m_gurnard(java.lang.String,long) for (int i=0; i<13; i++) { ^ C:\Users\Yo\Documents\Filicite.java:17: i is already defined in m_gurnard(java.lang.String,long) for (int i=0; i<13; i++) { ^ C:\Users\Yo\Documents\Filicite.java:18: incompatible types found : int required: boolean if (b = a_raisiny[i]) num[i]++; ^ C:\Users\Yo\Documents\Filicite.java:24: cannot find symbol symbol : variable num location: class Filicite if (num [i]<55 && num [i]>60) break; ^ C:\Users\Yo\Documents\Filicite.java:24: cannot find symbol symbol : variable num location: class Filicite if (num [i]<55 && num [i]>60) break; ^ C:\Users\Yo\Documents\Filicite.java:28: cannot find symbol symbol : method read() location: class java.lang.String for (int j=0; Exercise.read()<500; j++) { ^ C:\Users\Yo\Documents\Filicite.java:31: sum is already defined in m_gurnard(java.lang.String,long) long sum = su; ^ C:\Users\Yo\Documents\Filicite.java:35: cannot find symbol symbol : constructor InputStreamReader(java.lang.String) location: class java.io.InputStreamReader InputStreamReader isr = new InputStreamReader(Characters); ^ C:\Users\Yo\Documents\Filicite.java:36: cannot find symbol symbol : method length() location: class java.io.InputStreamReader long x = isr.length(); ^ 10 errors