0% found this document useful (0 votes)
31 views13 pages

Project Main

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views13 pages

Project Main

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

ACKNOWLEDGEMENT

I want to be really grateful to my computer teacher Mrs.


Fancy Roy Choudhury and our Council ISC for providing such
an informative project to us. While doing this project, it helped
me a lot as all of my doubts were getting cleared as I was
progressing in this project.
I also thank to my fellow friends, parents and my tuition
teacher for helping me in doing this project. They motivated me,
guided me and helped me all through the project and complete
in limited time.
I have done this project not only for marks but to increase my
knowledge in this particular subject.
Last but not least once again I want to thank to all who helped
me, and motivated me and guided me while doing my project.

INTRODUCTION TO JAVA

Page 1
Java is an object-oriented, class-based programming language. The
language is designed to have as few dependencies implementations as
possible. The intention of using this language is to give relief to the
developers from writing codes for every platform. The term WORA,
write once and run everywhere is often associated with this language. It
means whenever we compile a Java code, we get the byte code (.class
file), and that can be executed (without compiling it again) on different
platforms provided they support Java. In the year 1995, Java language
was developed. It is mainly used to develop web, desktop, and mobile
devices. The Java language is known for its robustness, security, and
simplicity features. That is designed to have as few implementation
dependencies as possible.

Patrick Naughton, Mike Sheridan, and Jame Gosling, known as the


Green team, started the development of Java in the year 1991. These
people were the engineers at Sun Microsystems. In 1996, the first public
implementation was released as Java 1.0. The compiler of Java 1.0 was
rewritten by Arthur Van Hoff to comply strictly with its specification.
With the introduction of Java 2, the new versions have multiple different
configurations that have been built for the various platforms. It is worth
noting that James Gosling is also known as the father of Java.

The ISO standard body was approached by Sun Microsystems in the


year 1997 to formalize Java, but the process was withdrawn soon. At
one point in time, Sun Microsystems provided most of its implementation
of Java available without any cost, despite having the status of
proprietary software.

PROGRAMS
CLASS BASED:-

Page 2
1. Write a program in Java to print all Prime Palindrome
numbers between ‘m’ and ‘n’.
Sample Execution:
Enter the value of m: 10
Enter the value of n: 760
Prime Palindrome numbers between 10 and 100 are:
11, 101, 131, 151, 191, 313, 353, 373, 383, 727, 757

import java.util.*;
public class Prime_Palin
{
public static void main()
{
Scanner sc=new Scanner(System.in);
int d,i,k,r,n,p,m,a,j;
System.out.println("Enter the value of m");
m=sc.nextInt();
System.out.println("Enter the value of n");
n=sc.nextInt();
System.out.println("Prime Palindrome numbers between "
+m+ " and " +n+ " are:");
for(i=m;i<=n;i++)
{
a=i;r=0;p=i;k=0;
do
{
d=a%10;
r=r*10+d;
a=a/10;

Page 3
}
while(a!=0);
if(r==p)
{
for(j=1;j<=p;j++)
{
if(p%j==0)
k=k+1;
}
if(k==2)
System.out.print(p + ",");
k=0;
}
}
}
OUTPUT OF THE PROGRAM:

2. Write a program in Java to print ‘n’ number of terms of


‘Automorphic’ numbers as entered by the users as a
response to: “Enter the number of terms of Automorphic
numbers to be displayed.”
Enter number of terms: 6
Automorphic numbers are: 1,5,6,25,76,376

Page 4
import java.util.*;
public class Automorphic
{
public static void main()
{
Scanner sc=new Scanner(System.in);
int n,i=1,j=0,i2,d=0,p;
double a,s;
System.out.println("Enter the number of automorphic
numbers to be displayed: ");
n=sc.nextInt();
System.out.println("Automorphic numbers are: ");
while(j<n)
{
s=(int)(Math.pow(i,2));
i2=i;
d=0;
while(i2>0)
{
i2/=10;
d++;
}
a=(Math.pow(10,d));
p=(int)(s%a);
if(i==p)
{
System.out.println(i);
j++;
}

Page 5
i++;
}
}
}
OUTPUT OF THE PROGRAM:

3. The MOBIUS FUNCTION M(N) for a natural number N is


defined as:
M(N) = 1 : if N=1
= 0 : if any prime factor of N is contained in N
more than once.
=(−1) : if N is a product of p distinct prime factors.
p

Page 6
Example:
M (78) = -1: for 78 = 2*3*13 so, M(78) = (−1) = -1.3

M (34) = 1 : for 34 = 2*17 so, M(34) =(−1) = 1.2

M (12) = 0 : for 12 = 2*2*3 so, M(12) =0, for 2 appears


two times.
M(17) = -1 : for 17 = M(17) = (−1) = -1, as 17 itself is a
1

prime number.
Write a program to input a positive natural number N and
output M(N). The program should continue till the user
wants.

import java.util.*;
public class Mobius
{
public static void main()
{
Scanner sc=new Scanner(System.in);
int j,p,n,c;
c=0;
double m;
m=0.0;
System.out.println("Enter a number :");
n=sc.nextInt();
if(n==1)
System.exit(1);
j=2;p=0;
while(j<=n)
{
if(n%j==0)

Page 7
{
c++;
n=n/j;
if(p>1)
{
m=0;
break;
}
}
else
{
j++;
p=0;
}
}
if(p<=1)
m=(Math.pow(-1,c));
System.out.println("The output of function is " +(int)m);
}
}

OUTPUT OF THE PROGRAM:

Page 8
4. Write a program in java to enter any number from 2 to 5
(both inclusive) and print all the combinations of digits
starting from 1 to that number. There should be one blank
space between each digit and each new combination should
appear on a new line. Also display the total number of
combinations formed for the given input.
Sample input:
Enter any number from 2 to 5 (both inclusive): 3
Sample Output:
123, 132, 213, 231, 312, 321.
Total number of combinations: 6.

import java.util.*;
public class Num_Combi
{
public static void main()
{
Scanner sc=new Scanner(System.in);
int n,c=0;

Page 9
char ch;
System.out.println("Enter a number between 2 to 5 (Both
inclusve) : ");
n=sc.nextInt();
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(i==j)
continue;
for(int k=1;k<=n;k++)
{
if(i==j || i==k || j==k)
continue;
for(int l=1;l<=n;l++)
{
if(i==j || i==k || i==l || j==k || j==l || k==l)
continue;
for(int m=1;m<=n;m++)
{
if(i==j || i==k || i==l || i==m || j==k || j==l || j==m
|| k==l || k==m || l==m)
continue;
System.out.println(i+ " " +j+ " " +k+ " " +l+ " " +m);
c++;
}
if(n==4)
{
System.out.println(i+ " " +j+ " " +k+ " " +l);
c++;

Page
10
}
}
if(n==3)
{
System.out.println(i+ " " +j+ " " +k);
c++;
}
}
if(n==2)
{
System.out.println(i+ " " +j);
c++;
}
}
}
System.out.println("Total number of combinations: "+c);
}
}
OUTPUT OF THE PROGRAM:

Page
11
Page
12
Page
13

You might also like