Showing posts with label JAVA. Show all posts
Showing posts with label JAVA. Show all posts

OOPS-Object Oriented Programming System




JAVA: 

        Java language is based on  Object oriented programming.Means in java we will be dealing with Class and Objects.


Principles of Java:

  1. Objects
  2. Class
  3. Encapsulation
  4. Abstraction
  5. Polymorphism
  6. Inheritance

0

Basics of Java Programming


Java Program Contains:

Java Program mainly contains 7 parts:
  1. Package declaration
  2. Import Statements
  3. Class declaration
  4. Variable declaration
  5. Constructor declaration
  6. Method declaration
  7. Static blocks.

Package Declaration:


0

Pyramid Pattern in Java


Example:



package patterns;

public class pyramid {
public static void main(String[] args) {


int spacecounter=4,starcounter=1;
for(int i=1;i<=5;i++)
{
System.out.println();
for(int j=1;j<=spacecounter;j++)
{
System.out.print(" ");
}

for(int k=1;k<=starcounter;k++)
{
System.out.print("*");
}

spacecounter--;
starcounter=starcounter+2;
}

}

}

Output:


     *
   ***
  *****
 *******
*********




0

Finding Largest,Second Largest,Lowest Number in ArrayList




Example:

package largestnumber;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.ListIterator;
import java.util.Scanner;

import org.apache.commons.collections.IteratorUtils;

public class highestnumber {

public static void main(String[] args) {
int i = 0;

ArrayList<Integer> arraylist = new ArrayList<>();
Scanner s = new Scanner(System.in);
System.out.println("Enter size of array:");
int n = s.nextInt();

System.out.println("You have to enter  " + (n - i) + " values:");
for (; i < n; i++)
 {
arraylist.add(s.nextInt());

}

Collections.sort(arraylist);
System.out.println("All Elements in the Array List are: " +arraylist);
System.out.println("Lowest Number in the  Array is:"
+ arraylist.get(0));
System.out.println("Second Largest Number in the Array is: "
+ arraylist.get(arraylist.size() - 2));
System.out.println("Largest Number in the Array is: "
+ arraylist.get(arraylist.size() - 1));

}

}


Output:

Enter size of array:
5
You have to enter  5 values:
3452
7865
9783
1748
9934

All Elements in the Array List are: [1748, 3452, 7865, 9783, 9934]
Lowest Number in the  Array is:1748
Second Largest Number in the Array is: 9783
Largest Number in the Array is: 9934


0

Pattern Example in Java :Pattern2




Pattern Design Format in Java


Example: 

0

Pattern Example in Java


Patterns Designing in Java Programming Most Easy Way To Design Pattern .















Example:

0