diff --git a/Abstract.java b/Abstract.java new file mode 100644 index 0000000..d493809 --- /dev/null +++ b/Abstract.java @@ -0,0 +1,12 @@ +import myapp.main; + +abstract class aminal{ + void makesound(); +} + +public class Abstract { + public static void main(String[] args) { + + } + +} diff --git a/Animal.class b/Animal.class new file mode 100644 index 0000000..5fdb1fd Binary files /dev/null and b/Animal.class differ diff --git a/Area.class b/Area.class new file mode 100644 index 0000000..9c3e598 Binary files /dev/null and b/Area.class differ diff --git a/BubbleSort.java b/BubbleSort.java index 34a7d33..6d08677 100644 --- a/BubbleSort.java +++ b/BubbleSort.java @@ -1,8 +1,7 @@ import java.util.*; class BubbleSort { - - public static void printArray(int arr[]){ + public static void printArray(int arr[]){ for(int i=0; i arr[j+1]) { + //swap + int temp = arr[j]; + arr[j] = arr[j+1]; + arr[j+1] = temp; + } + } + } + printArray(arr); + } + } diff --git a/ButterflyPattern.class b/ButterflyPattern.class new file mode 100644 index 0000000..9ce428b Binary files /dev/null and b/ButterflyPattern.class differ diff --git a/ClassObject.java b/ClassObject.java new file mode 100644 index 0000000..f0826d3 --- /dev/null +++ b/ClassObject.java @@ -0,0 +1,21 @@ +class Student{ +String firstname = "anjali"; +int age=19; + + +Student(String s, int a ) { + firstname=s; + age=a; + + System.out.println(firstname+ " "+ age); +} + + +} + +public class ClassObject{ + public static void main(String args[]){ + Student obj = new Student("anjali", 15); + Student obj1 = new Student("ayushi", 15); + } +} \ No newline at end of file diff --git a/Constructor.class b/Constructor.class new file mode 100644 index 0000000..12152d1 Binary files /dev/null and b/Constructor.class differ diff --git a/Dog.class b/Dog.class new file mode 100644 index 0000000..5f9ca24 Binary files /dev/null and b/Dog.class differ diff --git a/Happy.java b/Happy.java new file mode 100644 index 0000000..64e8438 --- /dev/null +++ b/Happy.java @@ -0,0 +1,28 @@ + abstract class Payment{ + + abstract void pay(int a); + void succes(){ + System.out.println("paymemt done"); + } + +} + +class UpiPayment extends Payment{ + void pay(int a){ + System.out.println("upi via payment"+a); + } +} +class Netbanking extends Payment{ + void pay(int b){ + System.out.println("netbanking via payment"+b); +} +} +class Happy { + public static void main(String[]args){ + Payment obj=new UpiPayment(); + obj.pay(23000); + Payment obj1 =new Netbanking(); + obj1.pay(56000); + obj1.succes(); + } +} \ No newline at end of file diff --git a/Hello.java b/Hello.java new file mode 100644 index 0000000..b04b24a --- /dev/null +++ b/Hello.java @@ -0,0 +1,19 @@ +class Vehicle{ + void run(){ + System.out.println("runn karti hai"); + } +} + +class Bike extends Vehicle{ + void run(){ + System.out.println("ye bhi chalti hai"); + } +} + +public class Hello{ + public static void main(String[] args){ + Vehicle obj=new Bike(); + obj.run(); + } + +} \ No newline at end of file diff --git a/Inheritance.java b/Inheritance.java new file mode 100644 index 0000000..da5138f --- /dev/null +++ b/Inheritance.java @@ -0,0 +1,32 @@ +public class Inheritance{ + public static void main(String[] args) { + Puppy obj1 = new Puppy(); + obj1.cry(); + obj1.bark(); + obj1.lazy(); + + } +} + + + + +class Animal { + void cry(){ + System.out.println("cryingggggggg"); + } +} + + +class Dog extends Animal{ + void bark(){ + System.out.println("barkkkkkk"); + } +} + + +class Puppy extends Dog{ + void lazy(){ + System.out.println("cutieeeeeeee"); + } +} diff --git a/Inheritance3.java b/Inheritance3.java new file mode 100644 index 0000000..b87ef42 --- /dev/null +++ b/Inheritance3.java @@ -0,0 +1,27 @@ +public class Inheritance3{ + public static void main(String[] args) { + Monitor obj = new Monitor(); + obj.displayName(); + obj.displayClass(); + obj.checkDiscipline(); + + } +} + +class Person{ + void displayName(){ + System.out.println("anjali"); + } +} + +class Student extends Person{ + void displayClass(){ + System.out.println("i am in class"); + } +} + +class Monitor extends Student{ + void checkDiscipline(){ + System.out.println("discipline"); +    } +} diff --git a/Inheritance6.java b/Inheritance6.java index 1fe9113..81085d6 100644 --- a/Inheritance6.java +++ b/Inheritance6.java @@ -23,9 +23,9 @@ public class Inheritance6 { public static void main(String[] args) { Puppy myPuppy = new Puppy(); - + myPuppy.weep(); myPuppy.eat(); myPuppy.bark(); - myPuppy.weep(); +     } } \ No newline at end of file diff --git a/Main.java b/Main.java new file mode 100644 index 0000000..9656e10 --- /dev/null +++ b/Main.java @@ -0,0 +1,31 @@ + +class Animal { + void eat() { + System.out.println("This animal eats food."); + } +} + +// Derived class (inherits from Animal) +class Dog extends Animal { + void bark() { + System.out.println("The dog barks."); + } +} + +// Derived class (inherits from Dog) +class Puppy extends Dog { + void weep() { + System.out.println("The puppy weeps."); + } +} + +public class Main { + public static void main(String[] args) { + Puppy myPuppy = new Puppy(); + + + myPuppy.eat(); + myPuppy.bark(); + myPuppy.weep(); +    } +} \ No newline at end of file diff --git a/Object.java b/Object.java new file mode 100644 index 0000000..9c72598 --- /dev/null +++ b/Object.java @@ -0,0 +1,19 @@ +class Student { + String firstName="anjali"; + int age=19; + + + Student(String firstName,int age){ + this.firstName= firstName; + age=age; + + System.out.println(firstName+ " " + age); + } +} + +public class Object { + public static void main(String[] args) { + Student obj = new Student("anjali", 19); + Student obj1Student = new Student("ayushi", 15); + } +} \ No newline at end of file diff --git a/Overloading.java b/Overloading.java new file mode 100644 index 0000000..fa978d2 --- /dev/null +++ b/Overloading.java @@ -0,0 +1,22 @@ +class parent{ + void sum(int a){ + System.out.println("my name is anjaliii"+a); + } + + void sum(int a,int b){ + System.out.println(a+b); + } + void sum(int a, int b, int c){ + System.out.println(a+b+c); + } +} + + +class Overloading{ + public static void main(String[] args){ + parent obj =new parent(); + obj.sum(420); + obj.sum(420,20); + obj.sum(420,20,40); + } +} \ No newline at end of file diff --git a/Overloading2.java b/Overloading2.java new file mode 100644 index 0000000..3eeaad9 --- /dev/null +++ b/Overloading2.java @@ -0,0 +1,11 @@ +class Overloading2{ + int age=19; + void data(){ + System.out.println(this); + } + + public static void main(String[] args){ + Overloading2 obj=new Overloading2(); + obj.data(); + } +} \ No newline at end of file diff --git a/Overloading4.class b/Overloading4.class new file mode 100644 index 0000000..fd8cc01 Binary files /dev/null and b/Overloading4.class differ diff --git a/Overloading4.java b/Overloading4.java new file mode 100644 index 0000000..11f4c43 --- /dev/null +++ b/Overloading4.java @@ -0,0 +1,19 @@ +class Area { + void area(double radius){ + System.out.println("Area of circle:" + (Math.PI * radius * radius )); + } + void area(double length, double width){ + System.out.println("Area of Rectangle:" + (length* width)); + } + +} + +public class Overloading4 { + public static void main(String[] args){ + Area obj = new Area(); + + obj.area(10.0); + obj.area(3.5, 4); + + } +} \ No newline at end of file diff --git a/Parent.class b/Parent.class new file mode 100644 index 0000000..ffcdd8d Binary files /dev/null and b/Parent.class differ diff --git a/Problem5.java b/Problem5.java new file mode 100644 index 0000000..0ea6d53 --- /dev/null +++ b/Problem5.java @@ -0,0 +1,21 @@ +class Shape { + public void area() { + System.out.println("displays area"); + } +} + +class Triangle extends Shape { + public void area(int l, int h){ + System.out.println(1/2*l*h); + } +} + +class EquilateralTriangle extends Triangle{ + public static void main(String[] args) { + + } +} + + + + diff --git a/Question.java b/Question.java deleted file mode 100644 index 1497b32..0000000 --- a/Question.java +++ /dev/null @@ -1,21 +0,0 @@ -public class Question { - - public static void main(String args[]){ - int[] arr = {23,4,12,78,56,43,98,1}; - - int min = arr[0]; - int max = arr[0]; - - for(int i = 1; i max){ - max = arr[i]; - } - } - System.out.println("Mininum element:" + min); - System.out.println("Maximum element:" + max); - - } -} \ No newline at end of file diff --git a/Question2.java b/Question2.java deleted file mode 100644 index e3ee396..0000000 --- a/Question2.java +++ /dev/null @@ -1,19 +0,0 @@ -public class Question2 { - - public static void main(String args[]){ - int[] arr = {1,2,3,4,5}; - int[] reversed = new int[arr.length]; - - for (int i = 0; i < arr.length; i++){ - reversed[i] = arr[arr.length-1-i]; - } - - System.out.println("Reversed array" ); - for(int i = 0; i< reversed.length;i++){ - System.out.print(reversed[i] + " "); - } - - - - } -} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..0bb44a6 Binary files /dev/null and b/README.md differ diff --git a/SelectionSort.java b/SelectionSort.java index d3dcfcc..88496ff 100644 --- a/SelectionSort.java +++ b/SelectionSort.java @@ -9,7 +9,7 @@ public static void printArray(int arr[]){ public static void main(String args[]){ int arr[] = {7,8,3,1,2}; - //bubble sort + //SelectionSort for(int i=0; i arr=new ArrayList<>(); + arr.add("anjali"); + arr.add("priyanshi"); + arr.add("disha"); + arr.add("sneha"); + arr.add("friends"); + arr.set(3,"yoyo"); + //gi arr.clear(); + arr.remove(2); + System.out.println(arr); + + } + +} \ No newline at end of file diff --git a/count_frequency.class b/count_frequency.class new file mode 100644 index 0000000..707b873 Binary files /dev/null and b/count_frequency.class differ diff --git a/count_frequency.java b/count_frequency.java new file mode 100644 index 0000000..215ce12 --- /dev/null +++ b/count_frequency.java @@ -0,0 +1,18 @@ +public class count_frequency { + public static void main(String[] args) { + String str = "aaabbccccddddd"; + StringBuilder newStr = new StringBuilder(); + int count = 1; + for (int i = 0; i < str.length() - 1; i++) { + if (str.charAt(i) == str.charAt(i + 1)) { + count++; + // System.out.println(str.charAt(i)); + } else { + newStr.append(str.charAt(i)).append(count); + count = 1; + } + } + newStr.append(str.charAt(str.length() - 1)).append(count); + System.out.println(newStr); + } +} \ No newline at end of file diff --git a/ex.java b/ex.java new file mode 100644 index 0000000..fd6069e --- /dev/null +++ b/ex.java @@ -0,0 +1 @@ +public class except \ No newline at end of file diff --git a/exception.java b/exception.java new file mode 100644 index 0000000..f3bfa3b --- /dev/null +++ b/exception.java @@ -0,0 +1,13 @@ +public class exception{ + public static void main(String[] args) { + int a=10; int b=0; + try { + int c=a/b; + } catch (Exception e) { + System.out.println("we can not divide by zero"); + + } + System.out.println("hello cc"); + System.out.println("hii ac"); + } +} \ No newline at end of file diff --git a/exception2.java b/exception2.java new file mode 100644 index 0000000..44ed392 --- /dev/null +++ b/exception2.java @@ -0,0 +1,43 @@ +// public class exception2{ +// public static void main(String[] args) { +// int[] arr={2,1,2,34}; +// try { +// System.out.println(arr[6]); + +// } catch (Exception e) { +// System.out.println(e); +// } +// System.out.println("hello"); +// } +// } + + +// public class exception2{ +// public static void main(String[] args) { +// String str= null ; +// System.out.println(str.toUpperCase()); +// try { + +// } catch (Exception e) { +// System.out.println(e); + +// } +// } +// } + + + + +public class exception2{ + public static void main(String[] args) { + int[]arr= {1,2,3}; + try { + System.out.println(arr[5]); + } catch (Exception e) { + System.out.println("Exception occurred:" +e); + } + System.out.println("End of program"); + } +} + + diff --git a/exception3.java b/exception3.java new file mode 100644 index 0000000..7351d20 --- /dev/null +++ b/exception3.java @@ -0,0 +1,26 @@ +// public class exception3{ +// public static void main(String[] args) { +// String s= null; +// try { +// System.out.println(s.length()); + + +// } finally { +// System.out.println("finally block executed"); + +// } +// } +// } + + +public class exception3{ + public static void main(String[] args) { + int[] arr={1,-2,3,4,-5}; + int + int smallest = arr[0]; + int temp = 0; + int secsmallest=arr[1]; + for(int i=0;i