-->

Hello,This is me!

ITEngineer8995

Professional Coder Coding is my passion

About me

Hello

I'mITEngineer8995

Spatial Data Specialist

Do you want all of your codes in one place?? Then you are landed on the right blog... Here you will find varieties of codes of various languages starting from noob to advance with their samples. Do learn, execute and share your knowledge with others. Do visit my YouTube Channel for execution of these codes .

Experience

Video Clone Detector using Hadoop

2017-2018

A detector which differentiates copied videos from the original ones using Hadoop.

Portfolio

Java Program To Check Prime Number using While Loop

  

Java Program To Check Prime Number using While Loop

In this java program, we check whether the user input number is prime or not.

A prime number is a natural number greater than 1 that is not a product of two small natural numbers.

E.g. 2, 3, 5 etc are prime numbers.

Steps :

Step 1 : Import Scanner class

Step 2 : Create class PrimeChec

Step 3 : Create main method

Step 4 : Create variable temp

Step 5 : Create object of Scanner 

Step 6 : Ask the user to enter any number by using System.out.print method

Step 7 : Create variable num and store the user entered number in it.

Step 8 : Close the Scanner class

Step 9 : Initialize int i equals to 2

Step 10 : Apply while loop where i is smaller than equal to num divide by 2

Step 11 : Apply if where num mod i is equals equals to zero

Step 12 : Initialize isPrime to False

Step 13 : If isPrime is true then the number is prime else not

Step 14 : Print the number

Program :

import java.util.Scanner;

public class PrimeChecWhile 

    {

        public static void main(String[] args)

        {

            int temp;

            boolean isPrime = true;

            Scanner sc = new Scanner(System.in);

            System.out.println("Enter any number:");

            //capture the input in an integer

            int num = sc.nextInt();

            sc.close();

            int i = 2;

            while(i<=num/2)

            {

                if(num%i==0)

                {

                    isPrime = false;

                    break;

                }

                i++;

            }

            //If isPrime is true then the number is prime else not

        if(isPrime)

        System.out.println(num+"is a Prime Number");

        else

        System.out.println(num+"is not a Prime Number");

        }

        }

Output :

Enter any number:
19
19is a Prime Number

For execution of the same do visit my YouTube Channel :

https://youtu.be/jYxikmPpNb4

Java Program To Check Prime Number

 

Java Program To Check Prime Number

In this java program, we check whether the user input number is prime or not.

A prime number is a natural number greater than 1 that is not a product of two small natural numbers.

E.g. 2, 3, 5 etc are prime numbers.

Steps :

Step 1 : Import Scanner class

Step 2 : Create class PrimeChec

Step 3 : Create main method

Step 4 : Create variable temp

Step 5 : Create object of Scanner 

Step 6 : Ask the user to enter any number by using System.out.print method

Step 7 : Create variable num and store the user entered number in it.

Step 8 : Close the Scanner class

Step 9 : Apply for loop where i is equal to 2, i is greater than equal to num divide by 2 and increment i by 1
Step 10 : Store num % i in the variable temp

Step 11 : Apply if where temp is equal to zero

Step 12 : Initialize isPrime to False

Step 13 : If isPrime is true then the number is prime else not

Step 14 : Print the number

Program :

import java.util.Scanner;

public class PrimeChec 

    {

        public static void main(String[]args)

        {

            int temp;

            boolean isPrime = true;

            Scanner sc = new Scanner(System.in);

            System.out.println("Enter any number:");

            //capture the input in an integer

            int num = sc.nextInt();

            sc.close();

            for(int i=2; i<=num/2; i++)

            {

                temp = num%i;

                if(temp==0)

                {

                    isPrime=false;

                    break;

                }

            }

            //If isPrime is true then the number is prime else not

            if(isPrime)

                System.out.println(num + "is a Prime Number");

            else

                System.out.println(num + "is not a Prime Number");  

        }

}

Output :

Enter any number:
6
6is not a Prime Number

For execution of the same do visit my YouTube Channel :

Java Program To Break Integer into Digits

 

Java Program To Break Integer into Digits

In this Java Program, we break Integers into Digits

Here we use Scanner class to get input from the user. First While loop is use to count the digits in the input number and second while loop is use to extract the digits from the input number using modulus operator.

Step 1 : Import Scanner Class

Step 2 : Create a Class IntegerToDigit

Step 3 : Create main method

Step 4 : Initialize num, temp, digit and count and store 0 in count

Step 5 : Ask the user to enter any number

Step 6 : Store the user entered number into num variable

Step 7 : Close the Scanner class to avoid memory leaks

Step 8 : Create a copy of input number

Step 9 : Store the num into temp

Step 10 : Count the digits into the input number

Step 11 : Apply While loop where num is greater than zero

Step 12 : Divide num by 10 and store the result into num variable

Step 13 : Increment count by one.

Step 14 : Apply another while loop where temp is greater than zero and store the result of temp % 0 into digit.

Step 15 : Print the Digit

Step 16 : Divide temp by 10 and store the result into temp variable

Step 17 : Decrement count by one.

Program :

import java.util.Scanner;

public class IntegerToDigit {

    public static void main(String[]args)

    {

        int num, temp, digit, count = 0;

        //getting the number from user

        Scanner sc = new Scanner(System.in);

        System.out.print("Enter any number:");

        num = sc.nextInt();

        sc.close();

        //creating a copy of the input number

        temp = num;

        //counting digits int the input number

        while(num > 0)

        {

            num = num / 10;

            count++;

        }

        while(temp > 0)

        {

            digit = temp % 10;

            System.out.println("Digit at place "+count+" is:"+digit);

            temp = temp / 10;

            count --;      

        }

    }    

}

Output :

Enter any number:7891

Digit at place 4 is:1

Digit at place 3 is:9

Digit at place 2 is:8

Digit at place 1 is:7

For execution of the same do visit my YouTube Channel :

https://youtu.be/yYfE4xFPj4s

Java Program to Display Prime Numbers from 1 to n

 

















Java Program to Display Prime Numbers from 1 to n

In this Java Program, prime numbers from 1 to n are displayed to the user.

A prime number is a natural number greater than 1 that is not a product of two small natural numbers.

E.g. 2, 3, 5 etc are prime numbers.

Step 1 : Create main method and create the object of  Scanner.

Step 2 : Initialize i to zero and num to zero.

Step 3 : Create an empty String named primeNumbers

Step 4 : Ask the user to enter the value of n using System.out.print method

Step 5 : Store the object of Scanner class in  variable n

Step 6 : Close the Scanner 

Step 7 : Apply For loop where i is equal to 1,  i is less than equal to n and increment i by 1

Step 8 : Initialize counter to 0

Step 9 : Apply another for loop where num is equal to i, num is greater than equal to 1 and decrement num by 1 

Step 10 : Apply if statement where i % num == 0

Step 11 : Increment counter by 1 and store it in variable counter

Step 12 : Close both the for loops

Step 13 : Apply if statement where counter == 2

Step 14 : Append the Prime number to the String

Step 15 : Print the output

Program :

import java.util.Scanner;
public class PrimeNumbersTwo 
    {
        public static void main(String[]args)
        {
            Scanner sc = new Scanner(System.in);
            int i = 0;
            int num = 0;
            //Empty String
            String primeNumbers = "";
            System.out.println("Enter the value of n:");
            int n = sc.nextInt();
            sc.close();
        for(i = 1; i <= n; i++)
        {
            int counter = 0;
            for(num = i; num>=1; num--)
            {
                if(i%num == 0)
                {
                    counter = counter + 1;
                   
                }
            }
            if (counter == 2)
                
            {
                //Appended the Prime number to the String
                primeNumbers = primeNumbers + i + " ";
            }
        }
            System.out.println("Prime numbers from 1 to n are:");
            System.out.println(primeNumbers);
    
}
}

Output:

Enter the value of n:
150
Prime numbers from 1 to n are:
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 

For execution of the same do visit my YouTube Channel :


Java Program to Display Prime Numbers from 1 to 100

  

















Java Program to Display Prime Numbers from 1 to 100

In this Java Program, prime numbers from 1 to 100 are displayed to the user.

A prime number is a natural number greater than 1 that is not a product of two small natural numbers.

E.g. 2, 3, 5 etc are prime numbers.

Step 1 : Initialize i to zero

Step 2 : Initialize num to zero

Step 3 : Create an empty string named as primeNnumbers

Step 4 : Apply for loop where num is equal to i, num is greater than equal to 1 and decrement num

Step 5 : Apply if statement inside for loop where i mod num is equal equal to zero

Step 6 : Increment counter by one and store it in counter variable

Step 7 : Close the for loop

Step 8 : Apply if statement where counter is equal equal to 2

Step 9 : Append the prime number to the string

Step 10 : Print the output by using System.out.println method

Program :

public class PrimeNumbers {
    
    public static void main (String[] args)
    {
        int i =0;
        int num =0;
        //Empty String
        String primeNumbers = "";
        
        for(i = 1; i<=100; i++)
        {
            int counter = 0;
            for(num = i; num>= 1; num--)
            {
                if(i%num==0)
                {
                    counter= counter + 1;
                }
            }
            if(counter == 2)
            {
                //Appended the Prime number to the String
                        primeNumbers = primeNumbers + i + "";
               
            }
        }
        System.out.println("Prime numbers from 1 to 100 are:");
        System.out.println(primeNumbers);
    }
    
}

Output:

Prime numbers from 1 to 100 are:
2357111317192329313741434753596167717379838997

For execution of the same do visit my YouTube Channel :





Java Program to Display First 100 Prime Numbers

 

















Java Program to Display First 100 Prime Numbers 

In this Java Program, first 100 prime numbers are displayed to the user.

A prime number is a natural number greater than 1 that is not a product of two small natural numbers.

E.g. 2, 3, 5 etc are prime numbers.

Step 1 : Create main method 

Step 2 : Initialize variables n, status and num

Step 3 : Print "First 100 prime numbers are:" using System.out.println method 

Step 4 : Apply for loop in which i is equal to 2 and i should be greater and equal to 100

Step 5 : Apply nested for loop in which j is equal to 2 and j is less than equal to Math.sqrt(num)                          and increment j by 1.

Step 6 : Apply if statement inside nested for loop in which num mod of j should be equal to zero

Step 7 : Store zero in the status variable and break the if statement and close the nested for loop.

Step 8 : Apply if statement in which status is not equal to zero

Step 9 : Print the num and increment the i by 1

Step 10: Store 1 in the status variable and increment num by 1

Program :

public class PrimeNumberDemo2 {

    public static void main (String[] args)
    {
        int n;
        int status = 1;
        int num = 3;
        System.out.println("First 100 prime numbers are:");
        System.out.println(2);
        for(int i = 2; i <= 100;)
        {
            for(int j = 2; j <= Math.sqrt(num);j++)
             {
               if(num%j == 0)
                 {
                status = 0;
                break;
                 }
               
             }
            if(status !=0)
            {
                System.out.println(num);
                i++;
            }
            status = 1;
            num++;
        }
    }
}

Output :

First 100 prime numbers are:

2
3
5
7
11
13
17
19
23
29
31
37
41
43
47
53
59
61
67
71
73
79
83
89
97
101
103
107
109
113
127
131
137
139
149
151
157
163
167
173
179
181
191
193
197
199
211
223
227
229
233
239
241
251
257
263
269
271
277
281
283
293
307
311
313
317
331
337
347
349
353
359
367
373
379
383
389
397
401
409
419
421
431
433
439
443
449
457
461
463
467
479
487
491
499
503
509
521
523
541

For execution of the same do visit my You Tube Channel :

https://youtu.be/seUJ8P4dNqM






Java Program to Display First n Prime Numbers using Scanner

















Java Program to Display First n Prime Numbers using Scanner

In this Java Program, first n prime numbers are displayed using scanner.

A prime number is a natural number greater than 1 that is not a product of two small natural numbers.

E.g. 2, 3, 5 etc are prime numbers.

Step 1 : Import Scanner class

Step 2 : Create main method 

Step 3 : Initialize variables n, status and num for capturing the value of n

Step 4 : Create object of Scanner

Step 5 : Ask the user to enter the value of n

Step 6 : Store the enter value in the variable n

Step 7 : Apply if statement

Step 8 : Apply for loop of i & j

Step 9 : Print the Results

Program :

import java.util.Scanner;

public class PrimeNumberDemo {
    public static void main(String args[])
    {
        int n;
        int status = 1;
        int num = 3;
        //for capturing the value of n
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter the value of n:");
        //The entered value is stored in the var n
        n = sc.nextInt();
        if( n >= 1)
        {
            System.out.println("First "+n+" prime numbers are:");
            // 2 is prime number
            System.out.println(2);
            
        }
        for (int i = 2; i <= n;)
        {
            for (int j = 2; j <= Math.sqrt(num); j++)
            {
                if (num % j == 0)
                {
                    status = 0;
                    break;
                }
            }
            if( status != 0)
            {
                System.out.println(num);
                i++;
                
            }
            status = 1;
            num++;
        }
           
       
    }
    
}

Output :

Enter the value of n:

15

First 15 prime numbers are:

2
3
5
7
11
13
17
19
23
29
31
37
41
43
47

For execution of the same do visit my You Tube Channel :







Java Program To Find The Factorial Of A Number Using Recursion

  

Java Program To Find The Factorial Of A Number Using Recursion

In this Java Program, we calculate the factorial of the number using recursion.

Factorial of n is the product of all the positive descending integers. It is denoted by n!

For example : 4! = 4 * 3 * 2 * 1 = 24

Logic : fact = fact * i;

Step 1 : Create main method

Step 2  : Create variable factorial and store factorial of 4 in it.

Step 3  : Print the number

Step 4 : Create a static function which returns 1

Step 5 : Create recursion function which calls itself

Program :

public class FactorialDemo2 {

    public static void main(String[] args){

        int factorial = fact(4);

        System.out.println("Factorial of 4 is:"+factorial);

    }

    static int fact(int n)

    {

    int output;

    if(n==1){

        return 1;

    }

    //Recursion : Function calling itself

    output = fact(n-1)*n;

    return output;

    }

}

Output :

Factorial of 4 is : 24

For execution of the same do visit my YouTube Channel :

https://youtu.be/xGJ2VBxZuRc


Java Program To Find The Factorial Of A Number Using Recursion Entered By The User

 

Java Program To Find The Factorial Of A Number Using Recursion Entered By The User

In this Java Program, we calculate the factorial of the number using recursion entered by the user.

Factorial of n is the product of all the positive descending integers. It is denoted by n!

For example : 4! = 4 * 3 * 2 * 1 = 24

Logic : fact = fact * i;

Step 1 : Import Scanner Class

Step 2 : Create main method

Step 3 : Create scanner object for capturing the user input

Step 4 : Ask the user to enter the number

Step 5 : Store the entered value in the variable num

Step 6 : Call the user defined function fact

Step 7 : Print the number

Step 8 : Create a static function which returns 1

Step 9 : Create recursion function which calls itself

Program :

import java.util.Scanner;

public class FactorialDemo {

    public static void main(String[] args)

    {

        //Scanner object for capturing the user input

        Scanner sc = new Scanner(System.in);

        System.out.println("Enter the number:");

        //Store the entered value in variable

        int num =sc.nextInt();

        //Call the user defined function fact

        int factorial = fact(num);

        System.out.println("Factorial of entered number is:"+factorial);

    }

    static int fact(int n)

    {

        int output;

        if(n==1){

            return 1;

        }

                //Recursion: Function calling itself

        output = fact(n-1)*n;

        return output;

    }    

}

Output :

Enter the number:

5

Factorial of entered number is:120

For execution of the same do visit my YouTube Channel :

https://youtu.be/IBSxhMDbMrw


Java Program To Reverse a String Entered by the User

  

Java Program To Reverse a String Entered by the User

In this Java Program, we reverse a string entered by the user

Logic :  String reversed = reverseString(str);

Step 1 : Import Scanner Class

Step 2 : Create main method

Step 3 : Create variable str

Step 4 : Ask user to enter the username

Step 5 : Create the object of the Scanner Class

Step 6 : Store the user entered username in the variable str

Step 7 : Close the scanner class to avoid memory lea

Step 8 : Apply the logic

Step 9 : Print the reversed string

Step 10 : Create reversedString method

Step 11 : Apply if condition which says if str is empty then reverse string

Step 12 : Call the function recursively 

Program :

import java.util.Scanner;

public class JavaExample2 {

    public static void main(String[] args)

    {

        String str;

        System.out.println("Enter your username:");

        Scanner sc = new Scanner(System.in);

        str = sc.nextLine();

        sc.close();

        String reversed = reverseString(str);

        System.out.println("The reversed string is:"+reversed);

    }

    public static String reverseString(String str)

    {

        if(str.isEmpty())

            return str;

        //calling function recursively

        return reverseString(str.substring(1))+str.charAt(0);

    }

}

Output :

Enter your username:

how are you doing?

The reversed string is:?gniod uoy era woh

For execution of the same do visit my Youtube Channel :

https://youtu.be/GUoz8dR5d1E


Zara Zara Cover | Rehna Hai Tere Dil Mein

 ZARA ZARA



               SONG KEY : A MAJOR                                        CAPO : 7TH FRET
 

                CHORDS    :      A Major ,  D major,  F Major                                                                                

          

             STRUMMING PATTERN :

        

                                                        SONG 

Yuhi Baras Baras Kaali Ghata Barse, Ham Yaar Bheeg Jaaye, 

                        A                                                          D                          
Is Chahat ki Baarish Mein, Meri khuli khuli Laton ko Suljhaye

                         F                                                           A

Tu Apni Ungliyon Se, Me Toh Hu Ishi Khwayish Mein,

                          D                                                          F

Sardi Ki Raaton Me, Ham Soye Rahe Ek Chadar Mein,

      A             D                       F                                 D

Ham Dono Tanha Ho, Naa Koi Bhi Rahe Is Ghar Mein,

       A             D                        F                                D  


Zara Zara Behekta Hai, Mehekta Hai, Aaj Toh Mera,

         A                 D                     F                       D


Tan Badan, Mein Pyasi Hu, Mujhe Bhar Le Apni Baaho Mein,

           A                D                     F                        D

Haa Meri Kasam, Tujhko Sanam, Dur kahi Naa Jaa,

            A                           D                        F              D        
             
Yeh Duri, Kehti Hai, Pass Mere Aaja Re,

            A          D                  F             D 

MUSIC :

                  
               A          D                  F             D 

               A          D                  F             D 

Tadpaaye Mujhe Teri Sabhi Baatein, Ek Baar Aye Deewane,

             A                              D                         F                     D

Zhoota Hi Sahi, Pyaar Toh Kar,
   
    A           D            F           D  

Mein Bhuli Nahi Hasi Mulakatein, Baichain Karke Mujhko,

    A                           D                               F                   D

Mujhse Yu Na Fer Najar,  

     A         D        F        D        

Roothega Na Mujhse, Mere Sathiya Ye Vada Kar,

      A                   D                    F                       D                                              
Bin Tere Mushkil Hai, Jeena Mera Mere Dilbar,

       A                   D                    F                       D 

Zara Zara Behekta Hai, Mehekta Hai, Aaj Toh Mera,

         A                 D                     F                       D


Tan Badan, Mein Pyasi Hu, Mujhe Bhar Le Apni Baaho Mein,

           A                D                     F                        D

Haa Meri Kasam, Tujhko Sanam, Dur kahi Naa Jaa,

            A                           D                        F              D        
             
Yeh Duri, Kehti Hai, Pass Mere Aaja Re,

            A          D                  F             D 

MUSIC :

                  
               A          D                  F             D 

               A          D                  F             D

Visit My Youtube Channel For the Cover :

https://youtu.be/kmpyEVQLuwo

ITEngineer8995
India

SEND ME A MESSAGE

Search This Blog

Powered by Blogger.

Pages

Java Program To Check Prime Number using While Loop

   Java Program To Check Prime Number using While Loop In this java program, we check whether the user input number is prime or not. A prime...