Binary String to Hex String - java

I want to turn a string of binary to hexadecimal string
For example, I have a length of 24 binary string
"000100000010000000110000"
Convert hex becomes 0x10 0x20 0x30
How can I do?
I made reference to this: http: //stackoverflow.com/questions/25592084/converting-binary-string-to-a-hexadecimal-string-java
But I tried the results are not correct ...
I was wrong in what I ask?
int digitNumber = 1;
int sum = 0;
String binary = "00000001";
for(int i = 0; i < binary.length(); i++)
{
if(digitNumber == 1)
sum+=Integer.parseInt(binary.charAt(i) + "")*8;
else if(digitNumber == 2)
sum+=Integer.parseInt(binary.charAt(i) + "")*4;
else if(digitNumber == 3)
sum+=Integer.parseInt(binary.charAt(i) + "")*2;
else if(digitNumber == 4 || i < binary.length()+1)
{
sum+=Integer.parseInt(binary.charAt(i) + "")*1;
digitNumber = 0;
if(sum < 10)
System.out.print("0x"+sum);
else if(sum == 10)
System.out.print("A");
else if(sum == 11)
System.out.print("B");
else if(sum == 12)
System.out.print("C");
else if(sum == 13)
System.out.print("D");
else if(sum == 14)
System.out.print("E");
else if(sum == 15)
System.out.print("F");
sum=0;
}
digitNumber++;
}
}
The result is ...
0x00x1

Try this:
Integer.parseInt(binOutput, 2) instead of Integer.parseInt(binOutput)

//Here is my Solution:
package stringprocessing;
/**
*
* #author zayeed
*/
public class StringProcessing {
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int index = 0;
String bin = "0000000101100101011011100110011100000001000000000000000010101010010101100110010101100011011010010110110101100001001000000100111001100101011101000111011101101111011100100110101101110011001000000100100001000001010100110010000001001001010100110101001101010101010001010100010000100000010000010010000001010010010001010101000101010101010010010101001001000101010001000010000001010111010001010100010101001011010011000101100100100000010101000100010101010011010101000010000001000110010011110101001000100000010101000100100001000101001000000100011001001111010011000100110001001111010101110100100101001110010001110010000001000011010011110101010101001110010101000100100101000101010100110010111101000001010100100100010101000001010100110011101000100000010100000110100101101110011000010110110000101100001000000100000101011010001110110010000001000001010101000010000000000001111000000011000100110010001110100011000100110011001000000101000001001101001000000100111101001110";
String[] hexString = new String[bin.length() / 4];
for (int i = 0; i < bin.length() / 4; i++) {
hexString[i] = "";
for (int j = index; j < index + 4; j++) {
hexString[i] += bin.charAt(j);
}
index += 4;
}
for (int i = 0; i < bin.length() / 4; i++) {
System.out.print(hexString[i] + " ");
}
// System.out.println("\n" + bin.length());
String[] result = binaryToHex(hexString);
for (int i = 0; i < result.length; i++) {
System.out.print("" + result[i].toUpperCase());
}
System.out.println("");
}
public static String[] binaryToHex(String[] bin) {
String[] result = new String[bin.length];
for (int i = 0; i < bin.length; i++) {
result[i] = Integer.toHexString(Integer.parseInt(bin[i], 2));
}
//return Integer.toHexString(Integer.parseInt(bin[0], 2));
return result;
}
}

Related

Why do I see this weird symbol in place of characters in the char array in java?

output
I'm getting these weird symbols while trying to display this char array. Same problem in online compiler too. what to do?
It happened once to me in C++ too. Either it shows nothing or this. It's making me crazy.
package com.avishkar;
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
String S = "aeroplane";
char[] arr = new char[S.length()];
for (int i = 0; i < S.length(); i++) {
arr[i] = S.charAt(i);
}
Arrays.sort(arr);
// System.out.println(Arrays.toString(arr));
int count1 = 0, count2 = 0;
for (int i = 0; i < arr.length; i++) {
char x = arr[i];
if (x == 'a' || x == 'e' || x == 'i' || x == 'o' || x == 'u') {
count2++;
} else {
count1++;
}
}
char[] con = new char[count1];
char[] vow = new char[count2];
int k = 0, l = 0;
for (int i = 0; i < count1; i++) {
char x = arr[i];
if (x == 'a' || x == 'e' || x == 'i' || x == 'o' || x == 'u') {
vow[l] = x;
l++;
} else {
con[k] = x;
k++;
}
}
System.out.println(Arrays.toString(con));
System.out.println(Arrays.toString(vow));
int x = 0, y = 0;
char[] finArr = new char[count1 + count2];
for (int i = 0; i < finArr.length; i++) {
if (count1 > count2) {
if (i % 2 == 0) {
finArr[i] = con[x];
x++;
} else {
finArr[i] = vow[y];
y++;
}
} else {
if (i % 2 == 0) {
finArr[i] = vow[y];
y++;
} else {
finArr[i] = con[x];
x++;
}
}
}
String ans = "";
for (int i = 0; i < finArr.length; i++) {
ans += finArr[i];
}
if (count1 - count2 > 1 || count2 - count1 > 1) {
System.out.println("-1");
}
System.out.println(ans);
}
}
I modified your code to print out the hexadecimal value of the characters, rather than the characters themselves.
The output looks like this:
0 0 0 0
61 61 65 65 0
61 0 61 0 65 0 65 0 0
Your "unprintable" characters are hexadecimal zero, which is unprintable.
Here's the modified code.
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
String S = "aeroplane";
char[] arr = new char[S.length()];
for (int i = 0; i < S.length(); i++) {
arr[i] = S.charAt(i);
}
Arrays.sort(arr);
// System.out.println(Arrays.toString(arr));
int count1 = 0, count2 = 0;
for (int i = 0; i < arr.length; i++) {
char x = arr[i];
if (x == 'a' || x == 'e' || x == 'i' || x == 'o' || x == 'u') {
count2++;
} else {
count1++;
}
}
char[] con = new char[count1];
char[] vow = new char[count2];
int k = 0, l = 0;
for (int i = 0; i < count1; i++) {
char x = arr[i];
if (x == 'a' || x == 'e' || x == 'i' || x == 'o' || x == 'u') {
vow[l] = x;
l++;
} else {
con[k] = x;
k++;
}
}
for (char c : con) {
System.out.print(Integer.toHexString((int) c) + " ");
}
System.out.println();
// System.out.println(Arrays.toString(con));
for (char c : vow) {
System.out.print(Integer.toHexString((int) c) + " ");
}
System.out.println();
// System.out.println(Arrays.toString(vow));
int x = 0, y = 0;
char[] finArr = new char[count1 + count2];
for (int i = 0; i < finArr.length; i++) {
if (count1 > count2) {
if (i % 2 == 0) {
finArr[i] = con[x];
x++;
} else {
finArr[i] = vow[y];
y++;
}
} else {
if (i % 2 == 0) {
finArr[i] = vow[y];
y++;
} else {
finArr[i] = con[x];
x++;
}
}
}
String ans = "";
for (int i = 0; i < finArr.length; i++) {
ans += finArr[i];
}
if (count1 - count2 > 1 || count2 - count1 > 1) {
System.out.println("-1");
}
for (char c : ans.toCharArray()) {
System.out.print(Integer.toHexString((int) c) + " ");
}
System.out.println();
// System.out.println(ans);
}
}

How can I test credit numbers with hyphens (" -" ) to get it as INVALID . When I tried 4003-6000-0000-0014 i am getting errors

I cant get credit card numbers containing hymens as INVALID such as 4003-6000-0000-0014 must give me INVALID but its giving me errors of string.
public class prog {
public static void main(String[] args)
{
Scanner userInput = new Scanner(System.in) ;
System.out.println("How many credit card you want to check?");
int numOfCredit = userInput.nextInt() ;
int creditnumbers[] = new int[numOfCredit] ;
for (int i = 0 ; i<numOfCredit ; i++)
{
System.out.println("Enter credit card number "+(i+1)+": ") ;
String creditNumber = userInput.next() ;
validateCreditCardNumber(creditNumber);
}
}
private static void validateCreditCardNumber(String str) { // function to check credit numbers
int[] ints = new int[str.length()];
for (int i = 0; i < str.length(); i++) {
ints[i] = Integer.parseInt(str.substring(i, i + 1));
}
for (int i = ints.length - 2; i >= 0; i = i - 2) {
int j = ints[i];
j = j * 2;
if (j > 9) {
j = j % 10 + 1;
}
ints[i] = j;
}
int sum = 0;
for (int i = 0; i < ints.length; i++)
{
sum += ints[i];
}
if (sum % 10 == 0)
{
System.out.println("VALID");
}
else
{
System.out.println("INVALID");
}
}
}
I get these errors after running with hymens :
Exception in thread "main" java.lang.NumberFormatException: For input string: "-"
at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:68)
at java.base/java.lang.Integer.parseInt(Integer.java:642)
at java.base/java.lang.Integer.parseInt(Integer.java:770)
at testing/testing.prog.validateCreditCardNumber(prog.java:33)
at testing/testing.prog.main(prog.java:22)
you can replace in your string "-" with "" (blank) and then apply this function:
String card = "4003-6000-0000-0014";
Boolean t = check(card.replace("-",""));
public static boolean check(String ccNumber)
{
int sum = 0;
boolean alternate = false;
for (int i = ccNumber.length() - 1; i >= 0; i--)
{
int n = Integer.parseInt(ccNumber.substring(i, i + 1));
if (alternate)
{
n *= 2;
if (n > 9)
{
n = (n % 10) + 1;
}
}
sum += n;
alternate = !alternate;
}
return (sum % 10 == 0);
}

Why is null appearing in my output? - Java

I am writing this program and all of a sudden null appears in the output:
1-10 |null**********
11-20 |null**********
21-30 |null
31-40 |null
41-50 |null
it should be like this:
1-10 |**********
11-20 |**********
21-30 |
31-40 |
41-50 |
This is my code:
import java.util.Arrays;
public class Ex4Method {
public void Average(int[] a) {
int total = 0;
for (int i = 0; i < a.length; i++) {
total = total + a[i];
}
int average = total / a.length;
System.out.println(" ");
System.out.println("Average: " + average);
}
public void MaxAndRange(int[] b) {
int min = b[0];
int max = b[0];
for (int i = 0; i <= 19; i++) {
//System.out.println(i);
if (b[i] < min) {
min = b[i];
}
if (b[i] > max) {
max = b[i];
}
}
int range = max - min;
System.out.println("Maximum Number: " + max);
System.out.println("Range: " + range);
}
public void Median(int[] c) {
Arrays.sort(c);
double median = 0;
System.out.println("Median: " + median);
}
public void findMedian(int a[]) {
// First we sort the array
Arrays.sort(a);
double median;
if (a.length % 2 == 0) {
median = ((double) a[a.length / 2] + (double) a[a.length / 2 - 1]) / 2;
} else {
median = (double) a[a.length / 2];
}
System.out.println("Median: " + median);
}
public void Mode(int[] d) {
int maxValue = 0, maxCount = 0;
for (int i = 0; i < d.length; i++) {
int count = 0;
for (int j = 0; j < d.length; j++) {
if (d[j] == d[i]) {
count++;
}
}
if (count > maxCount) {
maxCount = count;
maxValue = d[i];
}
}
System.out.println("Mode: " + maxValue);
}
public void Histogram(int[] f) {
String[] asterisk = new String[6];
System.out.println("Histogram: ");
System.out.println(" ");
for (int i = 0; i <= f.length - 1; i++) {
if (f[i] >= 1 && f[i] <= 10) {
asterisk[1] += "*";
}
if (f[i] >= 11 && f[i] <= 20) {
asterisk[2] += "*";
}
if (f[i] >= 21 && f[i] <= 30) {
asterisk[3] += "*";
}
if (f[i] >= 31 && f[i] <= 40) {
asterisk[4] += "*";
}
if (f[i] >= 41 && f[i] <= 50) {
asterisk[5] += "*";
}
}
System.out.println(" 1-10 |" + asterisk[1]);
System.out.println("11-20 |" + asterisk[2]);
System.out.println("21-30 |" + asterisk[3]);
System.out.println("31-40 |" + asterisk[4]);
System.out.println("41-50 |" + asterisk[5]);
}
}
MAIN CLASS-
import TurtleGraphics.KeyboardReader;
public class ArrayEx4 {
public static void main(String[] args) {
KeyboardReader reader = new KeyboardReader();
Ex4Method object = new Ex4Method();
int[] nums = new int[20];
int i = 0;
System.out.print("Enter a number (1-50): ");
nums[i] = reader.readInt();
while (nums[i] >= 1 && nums[i] <= 50 && i < 19) {
i++;
System.out.print("Enter a number (1-50): ");
nums[i] = reader.readInt();
//occurences[nums[i]]++;
}
//for(int x=0;x<=4;x++) {
//System.out.println(occurences[x]);
//}
object.Average(nums);
object.MaxAndRange(nums);
object.findMedian(nums);
object.Mode(nums);
object.Histogram(nums);
}
}
Any suggestions? Thanks
This is the code right here:
public void Histogram(int[] f) {
String[] asterisk = new String[6];
System.out.println("Histogram: ");
System.out.println(" ");
for (int i = 0; i <= f.length - 1; i++) {
if (f[i] >= 1 && f[i] <= 10) {
asterisk[1] += "*";
}
if (f[i] >= 11 && f[i] <= 20) {
asterisk[2] += "*";
}
if (f[i] >= 21 && f[i] <= 30) {
asterisk[3] += "*";
}
if (f[i] >= 31 && f[i] <= 40) {
asterisk[4] += "*";
}
if (f[i] >= 41 && f[i] <= 50) {
asterisk[5] += "*";
}
}
System.out.println(" 1-10 |" + asterisk[1]);
System.out.println("11-20 |" + asterisk[2]);
System.out.println("21-30 |" + asterisk[3]);
System.out.println("31-40 |" + asterisk[4]);
System.out.println("41-50 |" + asterisk[5]);
}
More specifically, this part:
asterisk[i] += "*";
In Java, + operator for strings means concatenation, and both operands are converted to strings beforehand.
At the very beginning, new String[6] is filled with default values for String type, which, for any type inherited from java.lang.Object is a null value. When you concatenate using operators, the very first pass over any slot in the array will always encounter a null value.
And
String.valueOf(null) + "*"
will output "null*"

Loop structure for histogram

I'm trying to write a Java program that generates a histogram of asterisks for each occurrence of a value in an array.
If the elements are, respectively, 0,1,2,3,4,5,6,7,8,9 the output should have an asterisk for each occurrence. For example,
0:*
1:*
2:*
3:*
4:*
5:*
6:*
7:*
8:*
9:*
However, my output is
0:**********
1:
2:
3:
4:
5:
6:
7:
8:
9:
The following code below is my own.
public static void drawHistogram(double[] array) {
String count = "";
for (int i = 0; i < array.length; i++) {
if (array[i] >= 0 && array[i] < 1) {
count += "*";
} else if (array[i] >= 1 && array[i] < 2) {
count += "*";
} else if (array[i] >= 2 && array[i] < 3) {
count += "*";
} else if (array[i] >= 3 && array[i] < 4) {
count += "*";
} else if (array[i] >= 4 && array[i] < 5) {
count += "*";
} else if (array[i] >= 5 && array[i] < 6) {
count += "*";
} else if (array[i] >= 6 && array[i] < 7) {
count += "*";
} else if (array[i] >= 2 && array[i] < 8) {
count += "*";
} else if (array[i] >= 2 && array[i] < 9) {
count += "*";
} else if (array[i] >= 9 && array[i] < 10) {
count += "*";
} else if (array[i] >= 10 && array[i] < 11) {
count += "*";
}
}
for (int j = 0; j <= 10; j++) {
System.out.print(j + count);
count = "";
System.out.println();
}
}
How can I fix this issue?
This solution uses (int) Math.floor(array[i]) to choose the bracket into which to put the double value, thus getting rid of the multiple if-then-else statements. I've also used StringBuilder instead of String to make the repeated concatenation of asterisks a little more efficient.
public static void drawHistogram(double[] array) {
StringBuilder histoGram[] = new StringBuilder[11];
for (int i = 0; i < histoGram.length; i++) {
histoGram[i] = new StringBuilder();
}
for (int i = 0; i < array.length; i++) {
int bracket = (int) Math.floor(array[i]);
if (bracket >= 0 && bracket < histoGram.length) {
histoGram[bracket].append("*");
}
}
for (int j = 0; j < 11; j++) {
System.out.format("%02d: %s\n", j, histoGram[j].toString());
}
}
Test main method:
public static void main(String args[]) {
double[] testValues = new double[100];
for (int i = 0; i < 100; i++) {
testValues[i] = Math.random() * 11.0;
}
drawHistogram(testValues);
}
Sample output:
00: *******
01: ********
02: ***********
03: ************
04: ********
05: **********
06: *******
07: ********
08: **********
09: ************
10: *******
public static void drawHistogram(double[] array) {
String count[] = new String[array.length];
for (int i = 0; i < array.length; i++) {
if (array[i] >= 0 && array[i] < 1) {
count[0] = "*";
} else if (array[i] >= 1 && array[i] < 2) {
count[1] = "*";
} else if (array[i] >= 2 && array[i] < 3) {
count[2] = "*";
} else if (array[i] >= 3 && array[i] < 4) {
count[3] = "*";
} else if (array[i] >= 4 && array[i] < 5) {
count[4] = "*";
} else if (array[i] >= 5 && array[i] < 6) {
count[5] = "*";
} else if (array[i] >= 6 && array[i] < 7) {
count[6] = "*";
} else if (array[i] >= 2 && array[i] < 8) {
count[7] = "*";
} else if (array[i] >= 2 && array[i] < 9) {
count[8] = "*";
} else if (array[i] >= 9 && array[i] < 10) {
count[9] = "*";
} else if (array[i] >= 10 && array[i] < 11) {
count[10] = "*";
}
}
for (int j = 0; j <= 10; j++) {
System.out.print(j + count[j]);
System.out.println();
}
}
It seems that you are using only a single variable to count up the occurrences of numbers in this method. This results in you program showing that 0 has nine occurrences and the rest of the numbers have 0 occurrences. I agree with the user David Choweller in the comments, who suggested that you could use an array to solve this problem. However, another solution might be a HashMap, where you store the number as the key, and the string that you want to print out as the value. Then, you can use the loop through the numbers at the end as you do currently, and print out the values associated with them.
You can use a Java Hasmap :
int myArray[] = new int[]{1, 2, 1, 3, 3, 1, 2, 1, 5, 1};
public static void main (String args[]) {
HashMap<Integer, String> hash = new HashMap<>();
hash.put(5, "");
hash.put(4, "");
hash.put(3, "");
hash.put(2, "");
hash.put(1, "");
for (int i = 0; i < myArray.length; i++){
hash.put(new Integer(myArray[i]), hash.get(myArray[i])+"*");
}
for(Integer key: hash.keySet()){
System.out.println(key+": "+ hash.get(key));
}
}

I am trying to assign a number to each character

import java.util.Scanner;
public class Recursion
{
//variables to hold string values
public static String s1 = new String(new char[10]);
public static String s2 = new String(new char[10]);
public static String s3 = new String(new char[11]);
public static String charSet = new String(new char[11]);
//variables to hold number values
public static int numberOne;
public static int numberTwo;
public static int numberThree;
public static int maxCharCount;
public static int[] numberSet = new int[10];
//function which generates a number
public static void checkForEquality()
{
numberOne = numberTwo = numberThree = 0;
int i;
int j;
for (i = 0; i < s1.length(); i++)
{
for (j = 0; j < maxCharCount; j++)
{
if (s1.charAt(i) == charSet.charAt(j))
{
if (i == 0 && numberSet[j] == 0)
return;
//generate the number
numberOne = (numberOne * 10) + numberSet[j];
}
}
}
for (i = 0; i < s2.length(); i++)
{
for (j = 0; j < maxCharCount; j++)
{
if (s2.charAt(i) == charSet.charAt(j))
{
if (i == 0 && numberSet[j] == 0)
return;
//generate number
numberTwo = (numberTwo * 10) + numberSet[j];
}
}
}
for (i = 0; i < s3.length(); i++)
{
for (j = 0; j < maxCharCount; j++)
{
if (s3.charAt(i) == charSet.charAt(j))
{
if (i == 0 && numberSet[j] == 0)
return;
//generate the number
numberThree = (numberThree * 10) + numberSet[j];
}
}
}
}
public static void display(){
if (numberOne + numberTwo == numberThree) {
//display the output
int i=0;
System.out.println();
System.out.print(" Summation Puzzle solved. ");
System.out.print("n");
System.out.print(s1);
System.out.print("<==>");
System.out.print(numberOne);
System.out.print("n");
System.out.print(s2);
System.out.print("<==>");
System.out.print(numberTwo);
System.out.print("n");
System.out.print(s3);
System.out.print("<==>");
System.out.print(numberThree);
System.out.print("n");
//loop to show the result
for (i = 0; i < maxCharCount; i++)
{
System.out.println(charSet.charAt(i));
System.out.print("<==>");
System.out.print(numberSet[i]);
System.out.print("n");
}
System.exit(0);
}
}
//recursive function which will call itself
public static void Combinations(int indexCounter, int[] availableSet)
{
int i;
if (indexCounter != 0)
{
for (i = 0; i < 10; i++)
{
numberSet[indexCounter] = i;
if (availableSet[i] == 1)
{
availableSet[i] = 0;
Combinations(indexCounter + 1, availableSet);
availableSet[i] = 1;
}
}
}
if (indexCounter == maxCharCount)
checkForEquality();
}
public static void createCharSet()
{
int i;
int setIndex;
int present;
int j;
setIndex = 0;
for (i = 0; i < s1.length(); i++)
{
present = 0;
for (j = 0; j < setIndex; j++)
{
if (s1.charAt(i) == charSet.charAt(j))
{
present = 1;
}
}
if (present == 0)
{
charSet = StringFunctions.changeCharacter(charSet, setIndex++, s1.charAt(i));
}
}
for (i = 0; i < s2.length(); i++)
{
present = 0;
for (j = 0; j < setIndex; j++)
{
if (s2.charAt(i) == charSet.charAt(j))
{
present = 1;
}
}
if (present == 0)
{
charSet = StringFunctions.changeCharacter(charSet, setIndex++, s2.charAt(i));
}
}
for (i = 0; i < s3.length(); i++)
{
present = 0;
for (j = 0; j < setIndex; j++)
{
if (s3.charAt(i) == charSet.charAt(j))
{
present = 1;
}
}
if (present == 0)
{
charSet = StringFunctions.changeCharacter(charSet, setIndex++, s3.charAt(i));
}
}
maxCharCount = setIndex;
}
public static void calculateSummation()
{
int loop;
if (maxCharCount > 10)
{
System.out.print("Please check the input again");
return;
}
else
{
int[] avaliableSet = new int[10];
for (loop = 0; loop < 10; loop++)
{
avaliableSet[loop] = 1;
}
Combinations(0, avaliableSet);
}
}
//main method
public static void main(String[]args) {
Scanner scan = new Scanner(System.in);
System.out.print("Enter the first String :");
s1 = scan.next();
System.out.print("Enter the second String :");
s2 = scan.next();
System.out.print("Enter the thirsd String :");
s3 = scan.next();
createCharSet();
System.out.print(" result of your 3 three strings = ");
System.out.print(charSet);
calculateSummation();
checkForEquality();
display();
}
}
Every time I run the program it just assigns 0 to each value. I want to be able to assign a value from 1-10 to each non numeric character.
can someone help me out.?
it should look something like this
Sample output
First off, you may find debugging easier if you properly format your code. I remember you posting last night where you experienced similar issues resulting from syntax. You may find that your code is easier to read if you format it like this:
//function which generates a number
public static void checkForEquality(){
numberOne = numberTwo = numberThree = 0;
int i;
int j;
for (i = 0; i < s1.length(); i++){
for (j = 0; j < maxCharCount; j++){
if (s1.charAt(i) == charSet.charAt(j)){
if (i == 0 && numberSet[j] == 0)
return;
//generate the number
numberOne = (numberOne * 10) + numberSet[j];
}
}
}
for (i = 0; i < s2.length(); i++){
for (j = 0; j < maxCharCount; j++){
if (s2.charAt(i) == charSet.charAt(j)){
if (i == 0 && numberSet[j] == 0)
return;
//generate number
numberTwo = (numberTwo * 10) + numberSet[j];
}
}
}
Take a look at just this portion of your code and see if it still properly follows your algorithm. You may find an error which you could've located yourself with properly formatted code. If you take a look at a previous question of yours (which I answered) you'll find a helpful link that guides you to writing better code.
Also, I didn't try to compile this in my own IDE, but you should take a look at Eclipse. A lot of the small errors you're getting could be located automatically by Eclipse.

Categories