Posts

Showing posts with the label java

Java String Manipulation 28th Jan Practice 2 - input a string and check whether it is a palindrome or not

Image
Palindrome is a number or a string which when reversed is the same as the original.  import java.util.*; class Main {     public static void main(String[] args) { Scanner in = new Scanner(System.in); String s,s1=""; char ch; System.out.println("Enter a String"); s = in.next(); int l = s.length(); s = s.toUpperCase(); for(int i=l-1; i>=0; i--){     ch = s.charAt(i);     s1 = s1+ch; } System.out.println(s1); if(s1.equals(s)){     System.out.println("Palindrome");      } else System.out.println("Not a palindrome");     } }

Java String Manipulation 28th Jan Practice 1 - to accept a character and check whether it is a letter or not. If letter, then convert it to uppercase or lowercase. Also check whether it is letter or a special character

Image
Java Program to accept a character and check whether it is a letter or not. If letter, then convert it to uppercase or lowercase. Also check whether it is letter or a special character import java.util.*; class Main {     public static void main(String[] args) {         Scanner in = new Scanner(System.in);         char a;         System.out.println("Enter a character");         a = in.next().charAt(0);         if(Character.isLetter(a)){             System.out.println("Character "+ a+ " is letter");             if(Character.isUpperCase(a)){                 System.out.println(Character.toLowerCase(a));             }             else             System.out.println(Character.toUpperCase(a)); ...

Java Recursion Program Practise 5 - to input a number and print the sum of digits of the number

Image
Java Program to input a number and print the sum of digits of the number using Recursive Function import java.util.*; class Main {    int digit(int n){        if(n==0)        return 0;        else        return (n%10+digit(n/10));    }     public static void main(String[] args) {         Scanner in = new Scanner(System.in);         int a;         System.out.println("Enter the number whose sum of digit is desired using Recursive function");         a = in.nextInt();         Main ob = new Main();         System.out.println(ob.digit(a));                       } }

Java Recursion Program Practise 4 - to input a number and display sum from 1 to that number

Image
Java Program to input a number and display sum from 1 to that number using Recursion import java.util.*; class Main {     int add(int n){         if(n>0){             return (n + add(n-1));         }         else         return 0;     }     public static void main(String[] args) {         Scanner in = new Scanner(System.in);         int a;         System.out.println("Enter the number of which the sum is desired from 1 to the number n");         a = in.nextInt();         Main ob = new Main();       System.out.println( ob.add(a));              } }

Java Recursion Program Practise 3 - Raising base to power of index

Image
Java Program to input two number and raising the input number to the power of the another input using Recursive Function.  import java.util.*; class Main {     int power(int n, int p){         if(p==0)         return 1;         else {             return (n* power(n,p-1));         }     }     public static void main(String[] args) {         Scanner in = new Scanner(System.in);         int a, b;         System.out.println("Enter the number and the power to be raised using Recursion Function");          a = in.nextInt();         b = in.nextInt();         Main ob = new Main();         System.out.println(ob.power(a,b));              } }

Java Recursion Program Practise 2 - Fibonacci Series

Image
Java program to find the given term of Fibonacci Series using Recursion Function import java.util.*; class Main {          int fib(int n){         if(n==1){         return 0;         }         if(n==2){         return 1;         }         if(n>2){             return(fib(n-2)+fib(n-1));         }         else         return -1;     }     public static void main(String[] args) {         Scanner in = new Scanner(System.in);         int a;         System.out.println("Enter the number of terms of Fibonacci series to be displayed using Recursion function");         a = in.nextInt();         Main ob = new Main();   ...

Java Recursion Program Practise 1 - Factorial

Image
Java Program to find Factorial of given number using Recursion import java.util.*; class Main {          int fact(int n){         if(n==0)         return 1;         else{             return(n*fact(n-1));         }     }     public static void main(String[] args) {         Scanner in = new Scanner(System.in);         int a;         System.out.println("Enter a number to get the factorial with the help of recursion");         a = in.nextInt();         Main ob = new Main();        System.out.println(ob.fact(a));                                } }

Java program to convert Decimal Number to Binary Number

Image
Java program to convert Decimal Number to Binary Number I was reading the first chapter of my class eleventh textbook. While reading the chapter, I came across a topic "Conversion of Decimal Number System to Binary Number System". In that chapter, I found the method of converting the decimal number to the binary number. Decimal number system means the number system which is base 10 or uses 10 digits. Like the one we use in maths with digits from 0 to 9. Binary Number system means the number system that uses the base 2 or only 2 digits. The number system of 0s and 1s are called Binary Number System, which is also the language of computers. In programming, 0 means off or false and 1 means true or on. The method for converting the decimal number to binary number is:  First the number is divided by 2 and the remainder whether it is 0 or 1 is noted. The first remainder is called Least Significant Bit (LSB). Then the quotient of the number is again divided by 2 and the remainder is...

Translate