This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Arrays; | |
class BinarySearch{ | |
public static void main(String ... args){ | |
int [] array; | |
if(args.length!=0){ | |
array= new int [args.length-1]; | |
for(int i=0; i<args.length-1; i++){ | |
array[i]=Integer.parseInt(args[i]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
class SelectionSort{ | |
public static void main(String ... args){ | |
int [] unsorted; | |
if(args.length!=0){ | |
unsorted= new int [args.length]; | |
int i=0; | |
for(String s: args){ | |
unsorted[i++]=Integer.parseInt(s); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BubbleSort{ | |
public static void main(String [] args){ | |
int [] unsorted= {9,8,7,6,5,4,3,2,1}; | |
if(args.length!=0){ | |
unsorted= new int [args.length]; | |
for(int i=0; i<args.length; i++){ | |
unsorted[i]=Integer.parseInt(args[i]); | |
} | |
} | |
System.out.println("STARTING SORTING"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Arrays; | |
class RecursiveBinarySearch{ | |
static int elem; | |
static int passNumber=1; | |
public static void main(String ... args){ | |
elem=Integer.parseInt(args[args.length-1]); | |
int [] array; | |
if(args.length!=0){ | |
array= new int [args.length-1]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
class Fibonacci{ | |
public static void main(String ... args){ | |
Scanner sc= new Scanner(System.in); | |
System.out.println("Enter the number of terms you are interested in"); | |
int n=sc.nextInt(); | |
do{ | |
System.out.println(n+"th term is "+fib(n)); | |
System.out.println("And the sum is "+sum(n)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class IntegerBaseConversion{ | |
static String numbers= "0123456789abcdef"; | |
public static void main(String ... args){ | |
if(args.length!=2){ | |
int n= Integer.parseInt(args[0]); | |
int base= Integer.parseInt(args[1]); | |
System.out.println(convertBase(n, base)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public int triangle(int rows) { | |
if(rows==0) | |
return 0; | |
if(rows==1){ | |
return 1; | |
} | |
return triangle(rows-1)+rows; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public boolean array220(int[] nums, int index) { | |
if(index>=nums.length-1) | |
return false; | |
for(int i=index+1; i<nums.length; i++){ | |
if((nums[index]*10)==nums[i]){ | |
return true; | |
} | |
} | |
return array220(nums,index+1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PairStar{ | |
public static void main(String ... args){ | |
System.out.println(pairStar(args[0])); | |
} | |
public static String pairStar(String str) { | |
System.out.println(str); | |
if(str.length()<=1){ | |
return str; | |
} | |
int mid= str.length()/2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public int strCount(String str, String sub) { | |
int index=str.indexOf(sub); | |
int l= sub.length(); | |
if(index==-1){ | |
return 0; | |
} | |
return 1+ strCount(str.substring(0,index) | |
+str.substring(index+l, str.length()), sub); | |
} |
OlderNewer