method overloading

Write a program to check prime and apply method overloading property.

 

import java.util.Scanner; class P14MethodOverloading { public static void main() { System.out.println("Enter two integer"); Scanner in = new Scanner(System.in); int start= in.nextInt(); int stop= in.nextInt(); while(stop> start) { int i= checkPrime(start);// This is called invoking or calling function. if( start==i) System.out.print(" "+start); start++; } checkPrime(); } static int checkPrime(int a) { int i=2; while(a>i) { if( a % i ==0) break; i++; } return i; } static void checkPrime() { System.out.println("\n\n\n\n This is the Example of method overloading."); System.out.println(" We are declaring two function with same name but different arguments "); } }



For any desired program, please comment below. We will try our best to make that program available.


Comments

Popular Posts