Posts

BlueJ for ISCE Boards

Java programming comes naturally to some lucky few. But that's not the same for the majority of the population. Some need more help in understanding the concept than others. That's the reason why I created this blog. Going through my blog will help you get a better understanding of the concepts involved in Java programming. This blog was made with ICSE students in mind. The programs I've written are the recurring questions in ICSE board exams. All the programming was written and compiled in BlueJ. In case you haven't got BlueJ to practise on, you can download it for free from  here . Install the latest version of BlueJ and you're good to go. Important programs to try out 1.  Factorial of a number 2.  Prime Number 3.  Palindrome 4.  Automorphic Number 5.  Bubble Sort 6.  Selection Sort After you gain enough confidence, you can try out unsolved programming questions which are available on the internet. In case you have any doubts regarding the s

Factorial

This is a program to find the factorial of a number import java.io.*; class factorial { long fact(int n) { long f=1; for(int i=1;i<=n;i++) f=f*i; return f; } public void main()throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter the value of m and n"); int m=Integer.parseInt(br.readLine()); int n=Integer.parseInt(br.readLine()); long S=(fact(n)/fact(m))*fact(n-m); System.out.println("The value of S is "+S); }}

Prime number

This is a Java program to check whether a given number is prime or not. A prime number is a non-negative integer which is divisible only by 1 and itself. For example, Five being divisible by only one and five, is a prime number. Six, on the other hand is divisible by one, two, three and six and hence is not a prime number. PROGRAM CODE import java.io.*; class prime { public void main()throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter a number"); int a=Integer.parseInt(br.readLine()); int flag=0;   for(int i=2;i<=a/2;i++)                                               { if (a%i==0) { flag=1; break;}} if(flag==0) System.out.println("PRIME"); else System.out.println("NOT PRIME"); }}

Palindrome

/*Write a program to input a number.Find the sum of digits of the number and also check whether the number is a palindrome or not  */ import java.io.*; class palindrome { public static void main() throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter a number"); int n=Integer.parseInt(br.readLine()); int d,p=0,s=0,h=n;   do { d=n%10; s=s+d; p=p*10+d; n=n/10; } while(n!=0); System.out.println("The sum of the digits of the given number = "+s); if(p==h) System.out.println("The number is a palindrome"); else System.out.println("The number is not a palindrome"); } }    

Automorphic number

/* Write a program to check whether an entered number is an automorphic number or not.  * A number is said to be an automorphic number if it is present in the last digits of its square  */ import java.io.*; class automorphic { public static void main()throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int m,b,p; double r=0; System.out.println("Enter a number"); int n=Integer.parseInt(br.readLine()); m=n; p=m*m; int c=0; do { c++; m=m/10; }while(m!=0); int q= p%(int)Math.pow(10,c); if(n==q) System.out.println(n+" is an Automorphic number"); else System.out.println(n+" is not an Automorphic number"); }}

Bubble sort

/*  *Write a program to implement bubble sort on a list of names and numbers according to user's choice  */ import java.io.*; class bubble_sort { public void main()throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter your choice \n 1.Sorting names \n 2.Sorting numbers"); int ch=Integer.parseInt(br.readLine()); switch(ch) { case 1:System.out.println("Enter number of names"); int n=Integer.parseInt(br.readLine()); String s[]=new String[n]; System.out.println("Enter names"); for(int i=0;i<n;i++) s[i]=br.readLine(); String temp=""; for(int i=0;i<n-1;i++) { for(int j=0;j<n-i-1;j++) { if(s[j].compareTo(s[j+1])>0) { temp=s[j]; s[j]=s[j+1]; s[j+1]=temp; }}} System.out.println("Sorted array"); for(int i=0;i<n;i++) System.out.println(s[i]+" "); break; case 2:System.out.println("Enter number of numbers"); in

Selection sort

/*  *Write a program to implement selection sort on a list of names and numbers according to user's choice  */ import java.io.*; class sel_sort { public void main()throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter your choice \n 1.Sorting names \n 2.Sorting numbers"); int ch=Integer.parseInt(br.readLine()); switch(ch) { case 1:System.out.print("Enter number of names:"); int n=Integer.parseInt(br.readLine()); String s[]=new String[n]; System.out.println("Enter names"); for(int i=0;i<n;i++) s[i]=br.readLine(); int p; String min,temp; for(int i=0;i<n;i++) { min=s[i]; p=i; for(int j=i+1;j<n;j++) { if(s[j].compareTo(min)<0) { min=s[j]; p=j; } } temp=s[i]; s[i]=s[p]; s[p]=temp; } System.out.println("Sorted array"); for(int i=0;i<n;i++) System.out.println(s[i]+" "); break; case 2:System.out.print("Enter number