!
)perfect number:a positive integer that is equal to the sum of its proper
divisors.
2)Armstrong number : it is a number that is equal to the sum of cubes of its
digits. For example 0, 1, 153, 370, 371 and 407 are the Armstrong numbers.
EXAMPLE1:-*PALINDROME*
import java.util.Scanner;
class Palindrome {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("enter number :");
int k=sc.nextInt();int n=k;int rev=0;
while(n!=0){
int d=n%10;
rev=rev*10+d;
n=n/10;
}
if(k==rev){
System.out.println("palindrome");
}
else{
System.out.println("not");
}
}
}
EXAMPLLE2:-*ARMSTRONG*
import java.util.Scanner;
class Palindrome {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("enter number :");
int k=sc.nextInt();int n=k;int armst=0;
while(n!=0){
int d=n%10;
armst=d*d*d+armst;
n=n/10;
}
if(k==armst){
System.out.println("armstrong");
}
else{
System.out.println("not");
}
}
}
EXAMPLE3:-*PALINDROME IN RANGE*
import java.util.Scanner;
class Palindrome {
public static void main(String[] args) {
System.out.print("Palindrome numbers:");
for(int i=1;i<=1000;i++){
int n=i;
int rev=0;
int num=i;
while(num>0){
int d=num%10;
rev=rev*10+d;
num/=10;
}
if(n==rev){
System.out.print(i+" ");
}
}
}
}
EXAMPLE4:-*PERFECT NUMBER*
import java.util.Scanner;
class Palindrome {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("enter number :");
int k=sc.nextInt();int sum=0;
for(int i=1;i<=k/2;i++){
if(k%i==0){
sum=sum+i;
}
}
if(sum==k){
System.out.println("perfect number");
}
}
}
EXAMPLE5:-*HISTOGRAM PATTERN*(HALF CODE ONLY)
// Online Java Compiler
// Use this editor to write, compile and run your Java code online
import java.util.Scanner;
class HelloWorld {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("enter number:");
int n=sc.nextInt();int k=n;int count=0;int max=0;
while(k!=0){
if(max<k%10){
max=k%10;
}
k=k/10;
count++;
}
k=n;
System.out.println(max);
System.out.println(count);
while(count!=0){
for(int i=max;i>0;i--){
for(int j=count;j>0;j--){
}
}
}
}
}
*STRING CONSTANT POOL*:-string s2=new String("abc");string s3="abc"
*TRY AND CATCH BLOCKS*:-
try {
// Block of code to try
}
catch(Exception e) {
// Block of code to handle errors
}
eg:-
public class Main {
public static void main(String[ ] args) {
try {
int[] myNumbers = {1, 2, 3};
System.out.println(myNumbers[10]);
} catch (Exception e) {
System.out.println("Something went wrong.");
}
}
}
*WHAT IS DIFFERENCE BETWEEN FINAL,FINALLY AND FINALIZE?*
*DIFFERENCE BETWEEN THROW AND THROWS*
*COLLECTIONS*:-
It is a frame work which is used represent a group of objects in single entity.
Before collection array can be used which is used to represent agroup of objects in
single entity.
Arraylist i best choice,when our frequent operation is to retrival,beacuse its
implement RandomAccessInterface.
*ARRAYLIST*:-
It is resizable.
It can have duplicate values.
*GENERIC COLLECTION*:-
-allows homogenous elements only.
-introduced in java 1.5 ver.
*NON-GENERIC COLLECTION*:-
-allows heterogeneous elements.
-introduced in java 1.2 ver.
*LINKED LIST*:-
-is a class which is located in java.util package.
-allows duplicate elements.
-maintains order.
-allows null element.
-uses doubly linked list concept to store elements.
-default initial capacity of linked list is empty.
-best choice when our frequent operation is to insertion or deletion.
-onwards 1.5ver linked list can be used as queue implementation as well.
-linked list intro in java 1,2 ver.
Linkedlist list=new Linkedlist();
*VECTOR*:-
-allows duplicate element.
-maintains order.
-allows null elements.
-internally uses array concept to store elements.
-default initial capacity of vectore is !0 elements.
=increases its capacity with 2x size.
*STACK*:-
-Child class of vector.
-allows duplicate elements.
-maintains order.
-allows null elements.
-default initial capacity of stack will be emoty or zero.
*SET*:-
-cchild interface of collection interface.
-is parent interface of sortedset interface.
-set interface implemented by hashset and linkedhashset clazss.
-set interface doesn't allow duplicates elements.
*HASHSET*:-
-internally uses hash table to store all elements.
-does'nt maintain order due to hash table.
-does'nt allow duolicate elements.
*LINKEDHASHSET*:-
-DOES'NT ALLOW DUPLICATE ELEMENTS.
-does'nt maitain order.
-allow only one null element.
-allows heterogeneous element.
-increases its capacity with2x.
-can be used if our frequent operation is to searh and maintain order.
*SORTED SET*:-
does'nt allow duplicate elements.
does'nt
*TREESET*:-
-does'nt allow null element.
-does'nt allow duplicate elements.
-does'nt allow heterogeneous elements.
-does'nt maintain order.
*QUEUE*:-
-child interface of collection interface.
-parent interface of blockingqueue interface.
-directly implemented by priority queue and linkedlist class.
*SynchronousQueue*:-
-SynchronousQueue is bounded Queue.
-mostly used in bluetooth pairing or hotstar cricket.
*CONSTRUCTOR*:-
-file f=new file(String name);
-file f=new file(String Subdirectory,string name);
*FILEWRITER*:-
CONSTRUCTOR:-
-filewriter f=new filewriter(String name);
-filewriter f=new filewriter(String Subdirectory,string name);
-FILEWRITER IS NOT IN USE TO ANY OF THE PROGRAMMER BCOZ WE HAVE TO INSERRT LNE
SEPERATOR MANUALLY WHICH SUPPORTS SOME OF THE SYSTEM AND DO NOT SUPPORT TO MANY OF
THE SYSTEMS.
METHODS:-
1.write(int ch);
2.write(string s);
3.write(char[] ch);
4.flush();
5.close();
*FILEREADER*:-
CONSTRUCTOR:-
1.FileReader fw=new FileReader(String name);
2.FileReader fw=new FileReader(File f);
METHODS:-
1.int read();
2.int read(char[] ch);
3.