# 1)To print Hello on console.

class Hello { public static void main(String args[]) { System.out.println("Hello World!!"); } } output:C:\Users\Desktop\Java Prgs\java Hello Hello World!!

2)To print first 20 terms of fibonacci series.
package helloworld; import java.io.*; public class Fibonacci { public static void main(String[] args) { System.out.println("Representing the Fibonacci series.."); int[] seq=new int[21]; seq[1]=0; seq[2]=1; for(int i=3;i<=20;i++) { seq[i]=seq[i-1]+seq[i-2]; } for(int j=1;j<=20;j++) { System.out.print(seq[j]+" "); } } }

Output:: Representing the Fibonacci series.. 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 BUILD SUCCESSFUL (total time: 0 seconds)

3)To check the primality of a number.
package helloworld; import java.util.Scanner; public class Helloworld { public static void main(String[] args) { Scanner scan=new Scanner(System.in); System.out.println("Checking for primality of a number..."); System.out.println("Enter the number"); double num=scan.nextDouble(); System.out.println("number= "+num); int flag=0; double srt=Math.sqrt(num); System.out.println("Sqrt is: "+srt); for(int i=2;i<=srt;i++) { if(num%i!=0) {flag=0; continue; } else {flag=1; break; } } if(flag==1){ System.out.println("Not a prime number"); } else { System.out.println("It is a prime number"); } }

output:: run: for primality of a number... Enter the number 69 number= 69.0 Sqrt is: 8.306623862918075 Not a prime number BUILD SUCCESSFUL (total time: 1 second)

j<=i.Scanner. i++. class Reverse { public static void main(String args[]) { System.4)To print the reverse of the number.nextInt().println(s). int s=0. } digit[i]=a.out.util. } } .i=0. import java.print("enter the number ::").out. while(a>=10) { digit[i]=a%10. a=scan. a=a/10. int[] digit=new int[3]. the number is taken as input from the user.in). for(int j=0. int a.j++) s=((s*10)+(digit[j])). } System. Scanner scan=new Scanner(System.

int num. num=scan.util.OUTPUT 5)To calculate the occurrences of every digit in a number. int a.in). int[] digit=new int[10]. import java. Scanner scan=new Scanner(System.out.Scanner.the number is taken as an input from the user.print("enter the number ::"). class Occurences { public static void main(String args[]) { System. while(num>=10) { .nextInt().

case 9:digit[9]=(digit[9]+1).a=num%10. break. case 2:digit[2]=(digit[2]+1). switch(a) { case 0:digit[0]=(digit[0]+1). break. break. case 3:digit[3]=(digit[3]+1). break. break. case 5:digit[5]=(digit[5]+1). break. } num=num/10. break. case 7:digit[7]=(digit[7]+1). break. break. case 8:digit[8]=(digit[8]+1). . case 6:digit[6]=(digit[6]+1). break. case 4:digit[4]=(digit[4]+1). case 1:digit[1]=(digit[1]+1).

case 7:digit[7]=(digit[7]+1).i++) { .i<10. break. break. case 2:digit[2]=(digit[2]+1). case 9:digit[9]=(digit[9]+1). case 6:digit[6]=(digit[6]+1).} switch(num) { case 0:digit[0]=(digit[0]+1). break. case 3:digit[3]=(digit[3]+1). break. } for(int i=0. case 8:digit[8]=(digit[8]+1). break. case 5:digit[5]=(digit[5]+1). break. break. break. case 1:digit[1]=(digit[1]+1). break. break. case 4:digit[4]=(digit[4]+1).

class Account { Account() { Accountno=0. } } } OUTPUT 6)To maintain bank account. Extend Bank account details to current and saving account.Scanner.util.out. float balance.println("digit "+i+" has been repeated "+digit[i]+" times").System. name=" ". . importjava. } intAccountno. balance=0.

println("Your Account number is:"+Accountno). } Saving(intnum.out. } voidgetdata() { System. System. balance=0.String s) { Accountno=num. } } class Saving extends Account { Saving() { Accountno=0. name=" ".floatbal.println("The name of the account holder is:"+name). name=s.String name.out. System.out. } . } public voidswithdrawl(float wdraw) { if((balance-wdraw)>1000) { balance=balance-wdraw. public void deposit(float dep) { balance=(balance+dep).println("Your balance is:"+balance). balance=bal.

String s) { Accountno=num.println("There is not enough balance in your account to withdraw the given amount").else { System. balance=0. name=" ". name=s. } .println("There is not enough balance in your account to withdraw the given amount").out. } public void cwithdrawl(float wdraw) { if((balance-wdraw)>-10000) { balance=balance-wdraw.out. balance=bal. } Current(intnum. } } } class Current extends Account { Current() { Accountno=0. } else { System.floatbal.

c=scan.num.println("Enter your choice:1 for creating a new account.nextInt().out.dep. System. . floatbal. do { System. Current ob2=new Current(). ch=scan.println("Enter the name of the Account Holder:").p. int c.2 for deposit and 3 for withdrawl:").out. if(c==1) { System.choice.out.println("Enter the type of Account:(1 for savings and 2 for current):"). String str= scan. intch.nextInt().out.with. Scanner scan=new Scanner(System.next().} } class Bank { public static void main(String args[]) { Saving ob1=new Saving().in). if(ch==1) { do { System.println("Enter the Account number:").out.nextInt().println("Enter the Account Balance:"). System. num=scan.

getdata(). ob1.out. ob1.nextFloat().getdata(). dep=scan. if(c==1) { . }while(choice==0).out.2 for deposit and 3 for withdrawl:").str).bal=scan.println("Enter the amount to be deposited:"). } if(c==3) { System.deposit(dep).out.nextFloat().swithdrawl(with). choice=scan. with=scan.println("Enter the amount to be withdrawn:").bal.println("Do you want to continue:(press 0 for yes and 1 for no):"). } else { do { System.nextFloat(). ob1=new Saving(num. } System. ob1.out.nextInt().getdata().nextInt().println("Enter your choice:1 for creating a new account. c=scan. ob1. ob1. } if(c==2) { System.

System.out. System. ob2. ob2.println("Enter the name of the Account Holder:"). dep=scan. String str= scan. ob2. System.println("Enter the Account Balance:").str). ob2=new Current(num.nextInt().println("Enter the amount to be deposited:").nextFloat(). ob2.getdata(). p=scan.next(). } System.out. num=scan.println("Enter the Account number:").out. bal=scan.out.cwithdrawl(with).nextFloat().out. } if(c==3) { System.println("Do you want to continue:(press 0 for yes and 1 for no):"). }while(choice==0).deposit(dep). ob2. } System.nextInt().nextInt().nextFloat(). } if(c==2) { System.getdata(). with=scan.out. .getdata().bal. choice=scan.out.println("Enter the amount to be withdrawn:").println("Do you want to deal with another account:").

} } OUTPUT .} while(p==0).

util. package pack. public class Account .Scanner.7)To maintain Bank Account using packages. importjava.

System. } public void getdata() { System. . name=" ".println("Your Account number is:"+Accountno).util. public class Current extends Account { public Current() { Accountno=0.out.out. importjava.println("The name of the account holder is:"+name).println("Your balance is:"+balance).out. System. } intAccountno. balance=0. } } package pack.{ public Account() { Accountno=0. public void deposit(float dep) { balance=(balance+dep).Scanner. String name. balance=0. float balance.

. } public Current(intnum.println("There is not enough balance in your account to withdraw the given } } } amount”). balance=bal. } public void cwithdrawl(float wdraw) { if((balance-wdraw)>-10000) { balance=balance-wdraw. importjava. name=s.floatbal.util. balance=0. package pack.out. public class Saving extends Account { public Saving() { Accountno=0.Scanner.name=" ". name=" ". } else { System.String s) { Accountno=num.

String s) { Accountno=num. importjava.} public Saving(intnum. floatbal.dep.*. intch. name=s. } else { System.out.with. } public voidswithdrawl(float wdraw) { if((balance-wdraw)>1000) { balance=balance-wdraw.floatbal. balance=bal.num. Current ob2=new Current().p. . class Packages { public static void main(String args[]) { Saving ob1=new Saving().choice.println("There is not enough balance in your account to withdraw the given amount").util. } } } import pack.*.

str).out. Scanner scan=new Scanner(System.out.out.out. bal=scan.int c.out. ob1=new Saving(num.next().nextFloat(). do { System.nextFloat().println("Enter your choice:1 for creating a new account. .getdata().println("Enter the Account number:"). num=scan. ob1.println("Enter the name of the Account Holder:"). } if(c==2) { System.nextInt(). System.println("Enter the type of Account:(1 for savings and 2 for current):").nextInt(). ob1. System. if(c==1) { System.bal. c=scan. ch=scan.deposit(dep). String str= scan.in).nextInt().out.println("Enter the amount to be deposited:").2 for deposit and 3 forwithdrawl:”).println("Enter the Account Balance:"). if(ch==1) { do { System. dep=scan.

next(). }while(choice==0).nextFloat().out.println("Enter the Account number:").str).nextInt().println("Enter the amount to be withdrawn:").2 for deposit and 3 forwithdrawl:”). num=scan. System. c=scan. with=scan.nextFloat().nextInt().nextInt().swithdrawl(with).ob1.out.getdata(). ob1. . } if(c==3) { System. ob1.out. if(c==1) { System.bal. String str= scan. System. } System. } else { do { System.println("Enter your choice:1 for creating a new account.println("Enter the name of the Account Holder:").out.println("Do you want to continue:(press 0 for yes and 1 for no):").getdata(). ob2=new Current(num.println("Enter the Account Balance:"). choice=scan. bal=scan.out.out.

p=scan.cwithdrawl(with).getdata().nextFloat().nextFloat(). choice=scan.out.println("Enter the amount to be deposited:"). } System. } if(c==3) { System.out.nextInt(). with=scan.out. ob2.nextInt(). } while(p==0).deposit(dep).println("Do you want to continue:(press 0 for yes and 1 for no):"). dep=scan.getdata().out. } System.ob2. ob2. ob2.getdata(). }while(choice==0).println("Do you want to deal with another account:"). } } OUTPUT .println("Enter the amount to be withdrawn:"). ob2. } if(c==2) { System.