Sunday, October 10, 2010

BlueJ Programs on Prime and Pal Prime Numbers

Write a program using BlueJ to print the prime numbers from 2 to 100.


 class BlueJ
{
 public void show()
 {
 System.out.println("\nPrime numbers between 2 and 100 are as follows:");
 for( int i=2;i< =100;i++)
 {
  if(prime(i))
  System.out.print(" " + i);
 }
 }
  public boolean prime(int n)
 {
 int i;
 for(i=2;i< n;i++)
 {
 if(n%i==0)
 break;
}
if(i==n)
return true;
else
return false;
}
}

Write a program using BlueJ to find the largest even number and smallest odd number from a list of 'n' numder of terms given by the user and indicates the number of numerals to be accepted.
  
import java.io.*;
class BlueJ1
{
int arr[],n,max,min;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
public void takeData()throws IOException
 {
 System.out.println("\nEnter the number of values to be stored:");
 n=Integer.parseInt(br.readLine());
 arr=new int[n];
 for( int i=0;i< n;i++)
 {
   System.out.print("Enter value: " );
   arr[i]=Integer.parseInt(br.readLine());
  }
  }
  public void show()
 {
  max=1;
  min=2;
 for(int i=0;i< n;i++)
 {
 if(arr[i]%2==0 && max==1)
 max=arr[i];
 else if(arr[i]%2!=0 && min==2)
 min=arr[i];
 else if(arr[i]%2==0 && arr[i]>max)
 max=arr[i];
 else if(arr[i]%2!=0 && arr[i] < min)
 min=arr[i];
 }
 System.out.println("Minimum odd Number="+min);
 System.out.println("Maximum even Number="+max);
}
}

 Write a pragram using BlueJ to display the prime palindromes existing in the range of 100-500.
  
class BlueJ2
{
public void show()
 {
 System.out.println("The numbers which are prime and palindrome are:");
  for( int i=100;i< =500;i++)
 {
  if(palin(i) && prime(i))
   System.out.print(i+ " " );
  }
  }
  public boolean prime(int n)
 {
 int i;
 for(i=2;i< n;i++)
 {
 if(n%i==0)
 break;
 }
 if(i==n)
 return true;
 else
 return false;
}

  public boolean palin(int n)
 {
   int r=0;
 for(int i=n;i >0;i=i/10)
 {
 r=r*10+i%10;
 }
 if(r==n)
 return true;
 else
 return false;
}
}


Write a program using BlueJ to print the multiplication table from 11-15

 class BlueJ3
{
public void show()
 {
 System.out.println("The Multiplication Table from 11 to 15 as follows:");
  for( int i=11;i< =15;i++)
 {
 for(int j=1;j< =10;j++)
 {
    System.out.print(i*j+ " " );
  }
  System.out.println();
  }
 }
}

6 comments:

  1. can anyone pls help wid this pattern:

    6
    6 12
    6 12 18
    6 12 18 24.....till 'n' number of terms

    ReplyDelete
  2. Pl. check the posting of October 12,2010. You will get lot of programs including this program.

    ReplyDelete
  3. class BlueJx
    {
    public static void main(String args[])
    {
    BlueJx ob=new BlueJx();
    ob.show();
    }
    public void show()
    {
    int i,j;
    for(i=0;i<5;i++)
    {

    for(j=0;j<=i;j++)
    {
    if(i<=2)
    System.out.print("*");
    else
    System.out.print("#");

    }
    System.out.println();
    }
    }
    }

    ReplyDelete
  4. Can we provide time limit in blueJ cauze i am making a program of writing test sort of program where the user will have to write the following give lines given by me in a specific time, how will i??? this is just a beta vs. of my program.

    ReplyDelete
  5. This can be done easily in java using Thread. As thread is not included in ISC syllabus, I am not posting such a program here. If you need help, I can send the code to you

    ReplyDelete

Subscribe via email

Enter your email address:

Delivered by FeedBurner