Programs done by Arka "MBPS" Mukherjee....
Thank you Arka a.k.a. "Java.lang"
Whether a number is Prime or not
=========================
class PrimeA
{
public static void main(String args[])
{
boolean isprime=true;
int n;
n=Integer.parseInt(args[0]);
for(int i=2;i
{
if(n%i==0)
{
System.out.println("The no is not a prime"+" "+n);
isprime=false;
break;
}
}
if(n==2||isprime==true)
System.out.println("The no is a prime one and it is :"+" "+n);
}
}
Prime and Non-Prime Numbers within a range
==================================
this program shows you whether a number is prime or not within 50.
import java.io.*;
public class ModifiedPrime
{
public static void main(String args[])
{
boolean isprime=true;
for(int j=2;j<=50;j++)
{
isprime=true;
for(int i=2;i<=j;j++)
{
if(i==j)
{
System.out.println("The no is prime"+" "+i);
isprime=true;
break;
}
else
{
if(j%i==0)
{
System.out.println("The no is not a prime no"+" "+j);
isprime=false;
break;
}
}
if(isprime==true)
System.out.println("The no is prime"+" "+j);
}
}
}
}
Sorting
======
import java.io.*;
class ModifiedSorting
{
public static void main(String args[])throws IOException
{
int i,temp,j;
int a[]=new int[10];
for(i=0;i<10;i++)
{
try
{
a[i]=Integer.parseInt(args[i]);
}
catch(ArrayIndexOutOfBoundsException e)
{
System.out.print("");
}
}
for(i=0;i<10;i++)
{
for(j=i;j<10;j++)
{
if(a[i]>a[j])
{
temp=a[j];
a[j]=a[i];
a[i]=temp;
}
}
}
System.out.println("the required sorted array is");
for(i=0;i<10;i++)
{
if(a[i]!=0)
System.out.println(a[i]);
}
}
}
Here after you compile do not forget to pass the values while executing...
Like.....
java ModifiedString 10 11 4
Arka hats off to you for giving me the codes. Some credit goes to me also as I corrected some designing errors....
No comments:
Post a Comment