File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import java .util .Scanner ;
2+ public class BinarySearch {
3+ public static void main (String []args ) {
4+ Scanner sc = new Scanner (System .in );
5+
6+ String name []= new String [20 ];
7+ double height []= new double [20 ];
8+
9+
10+ for (int i =0 ;i <20 ;i ++){
11+ System .out .println ("Please enter Name " );
12+ name [i ]=sc .nextLine ();
13+
14+ System .out .println ("Please enter Height" );
15+ height [i ]=sc .nextDouble ();
16+ sc .nextLine (); //
17+ }
18+ System .out .println ("Please enter friend's height" );
19+ double search =sc .nextDouble ();
20+
21+ int lb ,ub ,mid =0 ;
22+ ub =height .length -1 ;
23+ lb =0 ;
24+ boolean check =false ; //flag
25+
26+ while (lb <=ub ){
27+
28+ mid = (ub +lb )/2 ;
29+
30+ if (search <height [mid ])
31+ lb = mid + 1 ;
32+
33+ else if (search ==height [mid ]){
34+ System .out .println ("Friend's name and height found at " +(mid +1 ));
35+ System .out .println (name [mid ]);
36+ System .out .println (height [mid ]);
37+ check =true ;
38+ break ;
39+ }
40+
41+ else
42+ ub = mid - 1 ;
43+ }
44+
45+ if (check !=true )
46+ System .out .println ("Friend's name and height not found" );
47+
48+ sc .close ();
49+ System .exit (0 );
50+ }
51+ }
52+
Original file line number Diff line number Diff line change 1+ import java .util .Scanner ;
2+ public class Details {
3+ public static void main (String []args ) {
4+
5+ Scanner sc = new Scanner (System .in );
6+
7+ String names []=new String [20 ];
8+ long roll []=new long [20 ];
9+ double per []=new double [20 ];
10+ double avg =0.0 ;
11+
12+ System .out .println ("DETAILS" );
13+ for (int i =0 ;i <20 ;i ++){
14+
15+ System .out .println ("Enter name : " );
16+ names [i ]=sc .nextLine ();
17+ System .out .println ("Enter roll number : " );
18+ roll [i ]=sc .nextLong ();
19+ sc .nextLine (); //
20+ System .out .println ("Enter percentage : " );
21+ per [i ]= sc .nextInt ();
22+ sc .nextLine (); //
23+ }
24+
25+ double sum =0.0 ;
26+ for (int i =0 ;i <20 ;i ++){
27+ sum +=per [i ];
28+ avg =sum /20.0 ;
29+ }
30+ System .out .println ();
31+ System .out .println ("Name\t \t RollNo.\t \t Percentage" );
32+ for (int i =0 ;i <20 ;i ++){
33+ System .out .println (names [i ]+"\t \t " +roll [i ]+"\t \t " +per [i ]);
34+ }
35+ System .out .println ();
36+ System .out .println ("Class average is " +avg );
37+ System .out .println ();
38+ sc .close ();
39+ }
40+ }
Original file line number Diff line number Diff line change 1+ //not fast
2+ public class Geek_CoPrime {
3+ public static void main (String []args ) {
4+ System .out .println (sum (3L ,3L ));
5+ }
6+ public static long sum (long N , long M ){
7+
8+ long fac =0 ;
9+
10+ for (long i =1 ;i <=(Math .max (M ,N ));i ++){ // sqrt for efficiency
11+ if (N %i ==0 && M %i ==0 ) // checks if `i` is factor of `M and N` or not
12+ fac =i ;
13+ }
14+ long sum =(N /fac )+(M /fac );
15+
16+ return sum ;
17+ }
18+
19+ }
Original file line number Diff line number Diff line change 1+
2+ import java .util .Scanner ;
3+ public class LinearSearch {
4+ public static void main (String []args ){
5+ Scanner sc = new Scanner (System .in );
6+ double arr []= new double [20 ];
7+ boolean flag =false ;
8+ System .out .println ("Input percentage of the class " );
9+ for (int i =0 ;i <20 ;i ++){
10+ arr [i ]=sc .nextDouble ();
11+ }
12+ System .out .println ("Enter topper's percentage" );
13+ double topper = sc .nextDouble ();
14+
15+ for (int i =0 ;i <20 ;i ++){
16+
17+ if (arr [i ]==topper ){
18+ System .out .println ("Percentage found it is at " +(i +1 )+" th position" );
19+ flag =true ;
20+ break ;
21+ }
22+ }
23+ if (flag ==false )
24+ System .out .println ("Percentage not found " );
25+
26+ sc .close ();
27+ }
28+ }
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ public class MaximaMinima {
55 static int count = sc .nextInt ();
66 static int arr [] = new int [count ] ;
77
8-
8+
99 public static int max (){
1010 int temp ;
1111 for (int i = 0 ; i < count ; i ++)
Original file line number Diff line number Diff line change 1+ import java .util .Scanner ;
2+
3+ public class Passwordvalid {
4+ public static void main (String []args ) {
5+ Scanner sc = new Scanner (System .in );
6+ int t = sc .nextInt ();
7+ sc .nextLine ();
8+
9+ while (t >0 ){
10+ int lc =0 ,uc =0 ,nc =0 ;
11+ String s = sc .nextLine ();
12+
13+ for (int i =0 ;i <s .length ();i ++){
14+
15+ if ((int )s .charAt (i )>=97 && (int )s .charAt (i )<= 122 )
16+ lc ++;
17+ if ((int )s .charAt (i )>=65 && (int )s .charAt (i )<=90 )
18+ uc ++;
19+ if ((int )s .charAt (i )>=48 && (int )s .charAt (i )<=57 )
20+ nc ++;
21+
22+ }
23+
24+ if (uc >=1 &&lc >=1 &&nc >=1 )
25+ System .out .println ("YES" );
26+ else
27+ System .out .println ("NO" );
28+
29+ t --;
30+ }
31+ sc .close ();
32+ }
33+ }
Original file line number Diff line number Diff line change 1+ import java .util .Scanner ;
12public class number_decreasing {
23 public static void main (String []args ) {
34 Scanner sc = new Scanner (System .in );
Original file line number Diff line number Diff line change 1-
2- import java .util .Scanner ;
31public class test {
4- public static void main (String []args ) {
5- Scanner sc = new Scanner ( System . in ) ;
2+ public static void main (String []args ){
3+ int i = 0 ;
64
7- char ch ='x' ;
8- int inte =9 ;
9- float point =0.2f ;
10- result = (ch /inte ) * (point *inte );
11- System .out .println (result );
12- sc .close ();
5+ for (i =0 ;i <10 ;i ++)
6+ System .out .println ("hello" );
137
14-
15- }
16- }
8+ for (i =0 ;i <10 ;i ++)
9+ System .out .println ("bye" );
10+ }
11+ }
12+
You can’t perform that action at this time.
0 commit comments