Our teacher really sux, he just wrote this down on the board but didn't explain the program :(...after a lot of search i finally understand what is try and catch but what is the meaning of byte b=new byte[255];
in this program ? and why the program is not working ??
class Stu{
private int rollno,semester;
private String name;
protected String input(){
int l=0;
byte b=new byte[255]; // what is this
String S;
try{
l=System.in.read(b,0,255); // i know what is try and catch but what is (b,0,255) ?
}
catch (Exception r){} // nothing in the catch :(
S=new String (b,0,l-2); // what is l-2 ??
return S;
}
protected void get(){
System.out.print ("Enter name:");
name=input();
System.out.print ("Enter Roll number: ");
rollno=Integer.parseInt(input());
System.out.print("Enter Semester: ");
semester=Integer.parseInt(input());
}
protected void show(){
System.out.print(name);
System.out.print(rollno);
}
}
class Stu1 extends Stu{
private int marks,tech;
protected void getdata(){
super.get();
tech=Integer.parseInt(super.input());
marks=Integer.parseInt(super.input());
}
protected void showdata(){
super.show();
System.out.println ("Technology: " + tech);
System.out.println ("Marks: " + marks);
}
}
class Stu1demo {
public static void main(String []args){
Stu1 S1 = new Stu1();
S1.getdata();
S1.showdata();
}
}
Errors:
Stu1demo.java:8: incompatible types
found : byte[]
required: byte
byte b=new byte[255];
^
Stu1demo.java:11: cannot find symbol
symbol : method read(byte,int,int)
location: class java.io.InputStream
l=System.in.read(b,0,255);
^
Stu1demo.java:14: cannot find symbol
symbol : constructor String(byte,int,int)
location: class java.lang.String
S=new String (b,0,l-2);
^
3 errors