help in java i cant compile this
hi to all i am new to java and i am doing homework
i must compile this but there is an error and i cant find were
can you help me please
i am using BlueJ and jdk
Code :
import java.io.*;
public class IO_Tester {
public static int readInt() {
byte b[] = new byte[16];
String str;
try{
System.in.read(b);
str = (new String(b)).trim();
return Integer.parseInt(str);
} catch (IOException e) {
System.out.println("Exception: " + e.toString());
return 0;
}
}
}
public static float readFloat() {
byte b[] = new byte[16];
String str;
try{
System.in.read(b);
str = (new String(b)).trim();
return Float.parseFloat(str);
} catch (IOException e) {
System.out.println("Exception: " +e.toString());
return 0;
}
}
public static String readString() {
byte b[] = new byte[32];
String str;
try {
System.in.read(b);
str = (new String(b)).trim();
return str;
} catch(IOException e) {
System.out.println("Exception: ")+e.toString());
return "";
}
}
public static boolean readBoolean() {
byte b[] = new byte[16];
String str;
try {
System.in.read(b);
str = (new String(b)).trim();
Boolean bool = new Boolean(str);
return bool.booleanValue();
} catch (IOException e) {
System.out.println("Exception: " +e.toString());
return false;
}
}
Re: help in java i cant compile this
Hey timeline,
Welcome to the Java Programming Forums :)
There were a few small errors in your code. This should work:
Code :
import java.io.*;
public class IO_Tester {
public static int readInt() {
byte b[] = new byte[16];
String str;
try{
System.in.read(b);
str = (new String(b)).trim();
return Integer.parseInt(str);
} catch (IOException e) {
System.out.println("Exception: " + e.toString());
return 0;
}
}
public static float readFloat() {
byte b[] = new byte[16];
String str;
try{
System.in.read(b);
str = (new String(b)).trim();
return Float.parseFloat(str);
} catch (IOException e) {
System.out.println("Exception: " +e.toString());
return 0;
}
}
public static String readString() {
byte b[] = new byte[32];
String str;
try {
System.in.read(b);
str = (new String(b)).trim();
return str;
} catch(IOException e) {
System.out.println("Exception: " +e.toString());
return "";
}
}
public static boolean readBoolean() {
byte b[] = new byte[16];
String str;
try {
System.in.read(b);
str = (new String(b)).trim();
Boolean bool = new Boolean(str);
return bool.booleanValue();
} catch (IOException e) {
System.out.println("Exception: " +e.toString());
return false;
}
}
}
I've highlighted the errors below:
Code :
import java.io.*;
public class IO_Tester {
public static int readInt() {
byte b[] = new byte[16];
String str;
try{
System.in.read(b);
str = (new String(b)).trim();
return Integer.parseInt(str);
} catch (IOException e) {
System.out.println("Exception: " + e.toString());
return 0;
}
}
[B]}[/B]
public static float readFloat() {
byte b[] = new byte[16];
String str;
try{
System.in.read(b);
str = (new String(b)).trim();
return Float.parseFloat(str);
} catch (IOException e) {
System.out.println("Exception: " +e.toString());
return 0;
}
}
public static String readString() {
byte b[] = new byte[32];
String str;
try {
System.in.read(b);
str = (new String(b)).trim();
return str;
} catch(IOException e) {
System.out.println[B]("Exception: ")+e.toString());[/B]
return "";
}
}
public static boolean readBoolean() {
byte b[] = new byte[16];
String str;
try {
System.in.read(b);
str = (new String(b)).trim();
Boolean bool = new Boolean(str);
return bool.booleanValue();
} catch (IOException e) {
System.out.println("Exception: " +e.toString());
return false;
}
}
Re: help in java i cant compile this
thank for the help
Code :
import java.io.*;
public class IO_Tester {
public static int readInt() {
byte b[] = new byte[16];
String str;
try{
System.in.read(b);
str = (new String(b)).trim();
return Integer.parseInt(str);
} catch (IOException e) {
System.out.println("Exception: " + e.toString());
return 0;
}
}
public static float readFloat() {
byte b[] = new byte[16];
String str;
try{
System.in.read(b);
str = (new String(b)).trim();
return Float.parseFloat(str);
} catch (IOException e) {
System.out.println("Exception: " +e.toString());
return 0;
}
}
public static String readString() {
byte b[] = new byte[32];
String str;
try {
System.in.read(b);
str = (new String(b)).trim();
return str;
} catch(IOException e) {
System.out.println("Exception: "+e.toString());
return "";
}
}
public static boolean readBoolean() {
byte b[] = new byte[16];
String str;
try {
System.in.read(b);
str = (new String(b)).trim();
Boolean bool = new Boolean(str);
return bool.booleanValue();
} catch (IOException e) {
System.out.println("Exception: " +e.toString());
return false;
}
}
}
Re: help in java i cant compile this
Did this solve your issue timeline?
Re: help in java i cant compile this
Re: help in java i cant compile this
Quote:
Originally Posted by
timeline
yes thanks a lot
Glad I could help. I am marking this thread as solved.