Skip to content

Commit 43f21ba

Browse files
committed
Assignment
1 parent d319d7a commit 43f21ba

6 files changed

Lines changed: 127 additions & 55 deletions

File tree

‎BinarySearch.java‎

Lines changed: 0 additions & 27 deletions
This file was deleted.

‎Function_Overloading.java‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
public class Function_Overloading {
3+
4+
public static void num_cal(int num, char ch){
5+
if (ch=='s')
6+
System.out.println(num*num);
7+
else
8+
System.out.println(num*num*num);
9+
}
10+
public static void num_cal(int a,int b, char ch){
11+
if (ch=='p')
12+
System.out.println(a*b);
13+
else
14+
System.out.println(a+b);
15+
}
16+
public static void num_cal(char a, char b){
17+
if (a==b)
18+
System.out.println("Same Characters");
19+
else
20+
System.out.println("Different Characters");
21+
}
22+
23+
public static void main (String[]args) {
24+
25+
num_cal(4,'s');
26+
num_cal(5,6,'p');
27+
num_cal('c','c');
28+
29+
}
30+
}

‎LinearSearch.java‎

Lines changed: 0 additions & 28 deletions
This file was deleted.

‎PeakFinder.java‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import java.util.Scanner;
2+
3+
public class PeakFinder {
4+
5+
public static void findPeak(int array[], int len) {
6+
int peak[] = new int[len];
7+
for (int i = 1, j = 0; i < (array.length - 1); i++) { // 1 to 1 less than the length of the array
8+
if (array[i] > array[i + 1] && array[i] > array[i - 1] ) {
9+
peak[j] = array[i];
10+
j++;
11+
}
12+
if (array[0] > array[1] ) {
13+
int peakStart = array[0];
14+
System.out.println(peakStart);
15+
}
16+
}
17+
for (int k = 0; k < peak.length; k++) {
18+
if (peak[k]!=0) // blank indexes in dynamic array are not printed
19+
System.out.println(peak[k]);
20+
}
21+
22+
if (array[array.length-1] > array[array.length -2]) {
23+
int peakEnd = array[array.length-1];
24+
System.out.println(peakEnd);
25+
}
26+
}
27+
28+
public static void main(String[] args) {
29+
Scanner sc = new Scanner(System.in);
30+
System.out.println("Enter Number of elements in an array");
31+
int len = sc.nextInt();
32+
int array[] = new int[len];
33+
System.out.println("Enter elements");
34+
for (int i = 0; i < len; i++) {
35+
array[i] = sc.nextInt();
36+
}
37+
38+
findPeak(array, len);
39+
40+
sc.close();
41+
}
42+
43+
}

‎SeriesSumConflict.java‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import java.util.Scanner;
2+
public class SeriesSumConflict {
3+
// Same answer
4+
public static int SumSeries1(){ // Mine
5+
int s=0,prod=1;
6+
for (int i=1;i<=20;i++){
7+
prod*=i;
8+
s+=prod;
9+
}
10+
return s;
11+
}
12+
public static int SumSeries2(){ // Ma'am's
13+
int s=0,f=1;
14+
for (int i=1;i<=20;i++){
15+
f=1;
16+
for (int j=1;j<=i;j++){
17+
f*=j;
18+
}
19+
s+=f;
20+
}
21+
return s;
22+
}
23+
public static void main (String[]args) {
24+
Scanner sc = new Scanner(System.in);
25+
System.out.println(SumSeries1());
26+
System.out.println(SumSeries2());
27+
sc.close();
28+
}
29+
}

‎vowelCount.java‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import java.util.Scanner;
2+
3+
public class vowelCount {
4+
5+
public static int vowelCalc (String string){
6+
int vowelCounter=0;
7+
String vowels="";
8+
for (int i=0;i<string.length();i++){
9+
if (string.charAt(i)=='a'||string.charAt(i)=='e'||string.charAt(i)=='i'||string.charAt(i)=='o'||string.charAt(i)=='u'){
10+
vowelCounter++;
11+
vowels=vowels+string.charAt(i)+" ";
12+
}
13+
14+
}
15+
System.out.println("Vowels in the string : "+vowels);
16+
return vowelCounter;
17+
}
18+
public static void main (String[]args) {
19+
Scanner sc = new Scanner(System.in);
20+
System.out.println("Enter a string");
21+
String string = sc.nextLine();
22+
System.out.println(vowelCalc(string));
23+
sc.close();
24+
}
25+
}

0 commit comments

Comments
 (0)