File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Load diff This file was deleted.
Original file line number Diff line number Diff line change 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+ }
Load diff This file was deleted.
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments