- import java.util.Scanner;
- public class BinarySearch {
-
- public static void main(String[] args) {
-
- Scanner myScanner=new Scanner(System.in);
-
- System.out.print("Enter the array index : ");
-
- int n=myScanner.nextInt();
-
- int[] arr=new int[n];
-
- System.out.print("Enter "+n+" numbers : ");
-
- for (int i = 0; i <n; i++) {
-
- arr[i]=myScanner.nextInt();
-
- }
-
- System.out.print("Enter search number : ");
-
- int s=myScanner.nextInt();
-
- int f,l,m;
-
- f=0;
-
- l=n-1;
-
- m=(f+l)/2;
-
- while(f<=l)
-
- {
-
- if(arr[m]==s){
-
- System.out.print("The number is found in the array & Location is : "+(m+1));
-
- break;
-
- }
-
- else if(arr[m]<s){
-
- f=m+1;
-
- }
-
- else{
-
- l=m-1;
-
- }
-
- m=(f+l)/2;
-
- }
-
- if(f>l){
- System.out.println("The number is not found in the array");
-
- }
- }
-
- }
-
- import java.util.Scanner;
-
- public class StringPalin {
-
-
- public static void main(String[] args) {
-
- Scanner myScanner=new Scanner(System.in);
-
- System.out.print("Enter the string : ");
-
- String str1=myScanner.nextLine();
-
- String rev="";
-
-
-
- for (int i = str1.length()-1; i>=0; i--) {
-
- rev=rev+str1.charAt(i);
-
- }
-
-
-
- if(str1.compareToIgnoreCase(rev)==0){ ////you can also use str1.equals(rev)
-
- System.out.println(str1+" is Palindrome");
-
- }else {
-
- System.out.println(str1+" is Not palindrome");
-
- }
-
- }
-
-
- }
-
- //Enter the string : Madam
-
- //Madam is Palindrome
- import java.util.Scanner;
-
- public class StringSwapping {
-
- public static void main(String[] args) {
-
- Scanner myScanner=new Scanner(System.in);
-
- String a,b,temp;
-
- a="Alamgir";
-
- b="Hossain";
-
- System.out.println("Before swapping : A = "+a+" and B = "+b);
-
- temp=a;
-
- a=b;
-
- b=temp;
-
- System.out.println("After swapping : A = "+a+" and B = "+b);
-
- }
-
- }
-
- //Before swapping : A = Alamgir and B = Hossain
-
- //After swapping : A = Hossain and B = Alamgir
- import java.util.Scanner;
-
- public class FactorialRecursion {
-
- public static void main(String[] args) {
-
- Scanner myScanner=new Scanner(System.in);
-
- System.out.print("Enter a number : ");
-
- int n=myScanner.nextInt();
-
- System.out.print("Factorial of "+n+" is : "+factorial(n));
-
- }
-
- static int factorial(int n)
-
- {
-
- int f;
-
- if(n==0){
-
- f=1;
-
- }else{
-
- f=n*factorial(n-1);
-
- }
-
- return f;
-
- }
-
- }
-
- //Enter a number : 5
-
- //Factorial of 5 is : 120
- import java.util.Scanner;
-
- public class FibonacciRecursion {
-
- public static void main(String[] args) {
-
- Scanner myScanner=new Scanner(System.in);
-
- //---------Input-------------
-
- System.out.print("Enter how many terms you want : ");
-
- int n=myScanner.nextInt();
-
- for (int i = 1; i <=n; i++) {
-
- System.out.print(fib(i)+"\t");
-
- }
-
- }
-
- //--------------Fibonacci method----------------
-
- static int fib(int n)
-
- {
-
- int f;
-
- if (n==1) {
-
- f=0;
-
- }else if(n==2){
-
- f=1;
-
- }
-
- else{
-
- f=fib(n-1)+fib(n-2);
-
- }
-
- return f;
-
- }
-
- }
-
- //Enter how many terms you want : 10
-
- //0 1 1 2 3 5 8 13 21 34
-
-
-
- package SolveProblem;//Package name---------
-
- import java.util.Scanner;
-
- public class SelectionSort {
-
- public static void main(String[] args) {
-
- Scanner myScanner=new Scanner(System.in);
-
- //-----------------input----------------
-
- System.out.print("Enter how many number : ");
-
- int n=myScanner.nextInt();
-
- int[] arr=new int[n];
-
- int i;
-
- System.out.print("Enter "+n+" numbers : ");
-
- for (i = 0; i < n; i++) {
-
- arr[i]=myScanner.nextInt();
-
- }
-
- int pos,temp,j,k;
-
- // -----------sort start-------------
-
- for (k = 1; k < n; k++) {
-
- pos=k-1;
-
- for (j = k; j < n; j++) {
-
- if (arr[pos]>arr[j]) {
-
- pos=j;
-
- }
-
- }
-
- //-----------when position in not equal with k-1 then interchange--------------
-
- if(pos!=k-1){
-
- temp=arr[k-1];
-
- arr[k-1]=arr[pos];
-
- arr[pos]=temp;
-
- }
-
- }
-
- // ----------------------output------------------
-
- System.out.print("Sorted list is : ");
-
- for (i = 0; i <n; i++) {
-
- System.out.print(arr[i]+"\t");
-
- }
-
- System.out.println();
-
- }
-
-
- }
- import java.util.Scanner;
-
- public class abc {
-
- public static void main(String[] args) {
-
- Scanner myScanner=new Scanner(System.in);
- float num;
- System.out.print("Enter the number : ");
- num=myScanner.nextFloat();
- float ans=Math.round(num);
-
- System.out.println("The digit count is : "+ans);
-
- }
- }
-
- //Enter the number : 11.50
-
- //The digit count is : 12.0
- import java.util.Scanner;
-
- public class Power {
-
- public static void main(String[] args) {
-
- Scanner myScanner=new Scanner(System.in);
-
- System.out.print("Enter the number : ");
-
- int num=myScanner.nextInt();
-
- System.out.print("Enter power of : ");
-
- int power=myScanner.nextInt();
-
- long sum;
-
- sum=(long) Math.pow(num, power);
-
- System.out.println(num+" power "+power+" is : "+sum);
-
- }
-
- }
-
- //Enter the number : 25
-
- //Enter power of : 5
-
- //25 power 5 is : 9765625
- import java.util.Scanner;
-
- public class SumDigits {
-
- public static void main(String[] args) {
-
- Scanner myScanner=new Scanner(System.in);
-
- int n;
-
- System.out.print("Enter the number : ");
-
- n=myScanner.nextInt();
-
- int rem,sum=0;
-
- while (n!=0) {
-
- rem=n%10;
-
- sum=sum+rem;
-
- n=n/10;
-
- }
-
- System.out.println("Sum of digits of the given number is : "+sum);
-
- }
-
- }
-
- //Enter the number : 123456
-
- //Sum of digits of the given number is : 21
- import java.util.Scanner;
-
- public class ArmstrongBTNum {
-
- static int armstrong(int n)
-
- {
-
- int sum=0,rem,num,ck=0;
-
- num=n;
-
- while(num!=0)
-
- {
-
- rem=num%10;
-
- sum=sum+(rem*rem*rem);
-
- num=num/10;
-
- }
-
- return sum;
-
- }
-
-
-
- public static void main(String[] args) {
-
- Scanner myScanner=new Scanner(System.in);
-
- int a,b,i,ck;
-
- System.out.print("Enter two numbers : ");
-
- a=myScanner.nextInt();
-
- b=myScanner.nextInt();
-
- if(a>b){
-
- a=a+b;
-
- b=a-b;
-
- a=a-b;
-
- }
-
- System.out.print("Armstrong number are : ");
-
- for(i=a;i<=b;i++){
-
- ck=armstrong(i);
-
- if(ck==i){
-
- System.out.print(i+"\t");
-
- }
-
- }
-
- System.out.println();
-
- }
-
- }
-
- //Enter two numbers : 1 1000
-
- //Armstrong number are : 1 153 370 371 407