Experiment 1
Experiment 1
Experiment No. 1
AIM: Encapsulation
Program 1
PROBLEM Write a program using classes and objects to print all even and
STATEMENT :
of even and odd numbers in the given range.
ALGORITHM: 1)Create a class evenodd
2)In class, read n1 and n2
3)Create void function to print and count even numbers
4) Create void function to print and count odd numbers
5)Create public class ps1
6)In that class, create main function
7)Call even and odd function in main function
PROGRAM: import java.util.Scanner;
class evenodd
{
int n1, n2;
}
}
RESULT:
Program 2
class print
{
int n1, n2;
while (n > 0)
{
int a= n % 10;
arm += a * a * a;
n=n/10;
}
if(arm==i)
{
System.out.print(i+" ");
count++;
}
}
System.out.println();
System.out.println("total count of armstrong no.:" + co
}
for(int j=1;j<=i;j++)
{
if(i%j==0)
{
count++;
}
}
if(count==2)
{
System.out.print(i+" ");
c++;
}
}
System.out.println();
System.out.println("total count of prime no. "+c);
}
}
System.out.println("enter range");
A1.n1 = sc.nextInt();
A1.n2 = sc.nextInt();
System.out.println();
System.out.println("prime no.s are");
A1.prime(A1.n1,A1.n2);
}
}
RESULT:
CONCLUSION: I was able to learn object-oriented programming using java as well as how
to create the logic behind these two experiments.