Latest Government Jobs in India, Latest Engineering Jobs, Latest Banking Jobs, Latest State Government Jobs, Latest Defence/Police Jobs

Can someone tell me some basic java programs ?

QuestionsCan someone tell me some basic java programs ?
Sanjana Aggarwal asked 2 months ago

Hi, I am new to learn java. If any one of you have some basic programs of java. please share.

2 Answers
Facebook Profile photoVikas answered 2 months ago

Below mentioned is basic java program. hope this helps.
class Fb{
public static void main(String as[]){
String str;
int f1,f2=0,f3=1;
int upto=10;
try{
while(upto>1){
f1=f2;
f2=f3;
f3=f1+f2;
System.out.print(f3+” “);
upto–;
}
}catch(Exception e){
System.out.println(e);
}
}
}

Facebook Profile photoVikas answered 2 months ago

Here is another example :-
 
 
class Hello extends Exception{
Hello(){
System.out.println(“Hello from contructor”);
}
public String toString(){
return “HELLO EXCEPTION HAS OCCURRED”;
}
public String getMessage(){
return “not found something”;
}
}
class MyException{
public static void main(String as[]){
int x =10;
try{
if(x<20){
throw new Hello();
}
}
catch(Hello e){
System.out.println(e.getMessage());
}
}
}

Your Answer