Posts

S O M E | B A S I C | M E T H O D S | O F | S t r i n g | I N | J A V A :

Image
  S  T   R   I   N   G       M   E  T   H   O   D   S      i n         J     A     V    A (1)     How  to  read  String  and  char  ----->>>      .next();  |   .nextLine();  |   .next().charAt(0)      (2)   String  mein  se  koi  bhi  character  kaise  nikale                indexing  ki  help  se   ----->>>       .charAt(index)        (3)   How  to  read  any  ASCII  value  of  a  Character               from  a  given  String  ----->>>         ...

Recursion | Linear Search | Find all indices | Lecture 33 | Java and DSA Course

  J       A       V      A               C       O       D       E            1. Write a program to check  (x)  is exist or not in Array                  </>    RecArrayExistenceCheck.java        // METHOD (1) : // FINDING EXISTENCE OF AN ELEMENT : package Recursion ; import java.util.Scanner ; public class RecArrayExistenceCheck { public static void check ( int [] arr, int n, int x ) { if ( arr [ n ] ==x ) { System . out . println ( "YES" ) ; return ; } if ( n== 0 ) { System . out . println ( "NO" ) ; return ; } check ( arr,n- 1 ,x ) ; } public static void main ( String [] args ) { Scanner sc= new...

Recursion | Recursion on Arrays | Max Value | Sum of arrays | Lecture 32 | Java & DSA Course

  J    A    V    A             C    O    D     E        1. Write a program to print all the values in an Array Recursively             </>   RecArrayPrinting.java      // Printing ARRAY elements : package Recursion ; import java.util.Scanner ; public class RecArrayPrinting { public static void print ( int [] arr, int n ) { if ( n== 0 ) return ; print ( arr,n- 1 ) ; System . out . print ( arr [ n- 1 ] + " " ) ; } public static void main ( String [] args ) { Scanner sc= new Scanner ( System . in ) ; System . out . println ( "Enter no. of elements: " ) ; int n=sc. nextInt () ; int [] arr= new int [ n ] ; for ( int i= 0 ;i<n;i++ ) arr [ i ] =sc. nextInt () ; print ( arr,n ) ; ...

Recursion | GCD | Euclids Algorithm | Lecture 31 | Java & DSA Course

Image
J    A    V     A               C    O     D     E   1. Write a program to find Greatest Common Deviser (GCD) by using Recursion        </>   RecGcd1.java     // BRUTE FORCE APPROACH package Recursion ; import java.util.Scanner ; public class RecGcd1 { public static int find ( int x, int n1, int n2 ) { if ( n1%x== 0 && n2%x== 0 ) return x; return find ( x- 1 ,n1,n2 ) ; } public static void main ( String [] args ) { Scanner sc= new Scanner ( System . in ) ; System . out . println ( "Enter n1 and n2" ) ; int n1=sc. nextInt () ; int n2=sc. nextInt () ; int x; if ( n1<=n2 ) x=n1; else x=n2; int ans= find ( x,n1,n2 ) ; System . out . println ( ans ) ; sc. close () ...