Advertisement
Shailrshah

Implementing an Abstract Class

Oct 29th, 2013
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.56 KB | None | 0 0
  1. import java.util.Scanner;
  2. abstract class A{
  3.     public abstract void special(int n);
  4. }
  5. class B extends A{
  6.     public void special(int n){
  7.         int i, j;
  8.         for(i = 1000; i<=n; i++)
  9.             for(j = 1; j<i/2; j++)
  10.                 if(j*j == i){
  11.                     System.out.println(i+" is a perfect square.");
  12.                     break;
  13.                 }
  14.     }
  15. }
  16. class Squarenos{
  17.     public static void main(String[] args){
  18.         Scanner sc = new Scanner(System.in);
  19.         int n = 0;
  20.         while(n>1000 && n<9999){
  21.             System.out.println("Enter the a number in between 1000 and 9999: ");
  22.             n = sc.nextInt();
  23.         }
  24.         new B().special(n);
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement