Thursday, October 24, 2019

Finding Maximum and Minimun values from an Array



Program

package minmax;

public class MinMax
{
    public static void main(String[] args)
    {
        int a[] = {10,324,45,90,9808};
        int min = a[0];
        int max = a[0];
        for(int i =  0 ;  i <  a.length; i++)
        {
            if(a[i] >  max)
                max = a[i];
            if(a[i] < min)
                min = a[i];
        }
        System.out.println("Max value " + max);
        System.out.println("Min value " + min);
    }
   
}


Video explanation



Wednesday, October 23, 2019

Area and Perimeter of Rectangle

 

Question

You need to read two side values S1 and S2 from the user and calculate the area & perimeter of the rectangle using their side values and print the same.

Program

package area;
import java.util.Scanner;

public class Area
{
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        long s1 = in.nextLong();
        long s2 = in.nextLong();
        //long area = s1 * s2;
        //long perimeter = 2 * (s1 + s2);
        System.out.println("Area " + (s1 * s2));
        System.out.println("Perimeter " + (2*(s1 + s2)));
    }
   
}

Video explanation



Tuesday, October 22, 2019


Question

In this challenge, you must read an integer, a double, a string and a character from keyboard, then print the values

Program

package inout;

import java.util.Scanner;

public class Inout
{
    public static void main(String[] args)
    {
        Scanner in =  new Scanner(System.in);
        String s = in.nextLine();
        char c = in.nextLine().charAt(0);
        int x = in.nextInt();
        double d = in.nextDouble();
        System.out.println("Integer- " +  x);
        System.out.println("Double- " +  d);
        System.out.println("String- " + s);
        System.out.println("Char- " + c);
    }
   
}

Video explanation



Simple use of if - else

Question

Given an integer,n, perform the following conditional operations,

If n is odd, print Good

If n is even and in the inclusive range of 2 to 5, print Not Good

If n is even and in the inclusive range of 6 to 20, print Good

If n is even and greater than 20, print Not Good

Program

package ifelse;
import java.util.Scanner;
public class IfElse
{
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        if(N%2==1)
        {
            System.out.println("Good");
        }
        else
        {
            if(N >= 2 && N <= 5)
                System.out.println("Not Good");
            else if(N >= 6 && N <= 20)
                System.out.println("Good");
            else if(N > 20)
                System.out.println("Not Good");
        }
    }
}

Video  explanation




Sunday, October 20, 2019

Pattern printing 1

Expected pattern

 

* * * *
* * * *
* * * *
* * * *
* * * *

Program

#include<iostream>
using namespace std;
int main()
{
    for(int i = 1; i <= 5; i++)
    {
        for(int j = 1; j<= 4; j++)
        {
            cout<<"*";
        }
        cout<<endl;
    }
}

Video explanation

 

 

Sum of digits of a number



Program  

package sumofdigits;

public class SumOfDigits
{
    public static void main(String[] args)
    {
        int n = 34;
        int sum = 0;
        while(n > 0)
        {
            int temp = n % 10;
            sum = sum + temp;
            n = n / 10;
        }
        System.out.println(sum);
    }
   
}

Video  explanation



Count the number of Digits of a Number



Program

package digits;

public class Digits
{
    public static void main(String[] args)
    {
        int n = 34243;
        int count = 0;
        while(n > 0)
        {
            n = n / 10;
            count++;
        }
        System.out.println(count);
    }
}

Video explanation


Thursday, October 17, 2019

Fibonacci Series



Program


package fibo;
public class Fibo
{
    public static void main(String[] args)
    {
        int n = 10;
        int f = 1,s = 1,t;
        System.out.println(f);
        System.out.println(s);
        for(int i = 3; i<= n; i++)
        {
            t = f + s;
            System.out.println(t);
            f = s;
            s = t;
        }
    }
   
}

Video explanation

Find Factorial of a number



Program


package fact;

public class Fact
{
    public static void main(String[] args)
    {
        int n= 5;
        int fact = 1, i;
        for (i=2; i<=n; i++)
        {
            fact = fact * i;
        }
        System.out.println(fact);
    }
}


Video explanation



Check if a given year is Leap Year



Program


package leap.year;
import java.util.*;
public class LeapYear
{
    public static void main(String[] args) 
    {
        int year = 1996;
        // If a year is multiple of 400,
        // then it is a leap year
        if (year % 400 == 0)           
            System.out.println("Leap year");
        // Else If a year is muliplt of 100,
        // then it is not a leap year
        else if (year % 100 == 0)     
            System.out.println("Not leap year");
        // Else If a year is muliplt of 4,
        // then it is a leap year
        else if (year % 4 == 0)  
            System.out.println("Leap year");
    }
   
}

Video explanation



C++ program to Swap two numbers (Using extra variable)



Program 

#include<iostream>
using namespace std;

int main()
{
    int a = 105, b = 2;
    int temp;
    cout<<"Before swap "<<a<<" "<<b<<endl;
    temp = a;
    a = b;
    b =temp;

    cout<<"After swap "<<a<<" "<<b;

}

Video explanation


C++ program to find if a number is ODD or EVEN

Program

#include<iostream>
using namespace std;

int main()
{
    int number = 36;

    if(number % 2 == 0)
    {
        cout<<"Number is even";
    }
    else
    {
        cout<<"Number is Odd";
    }
}

Video explanation


C++ program to find Quotient and Remainder



 Program


#include<iostream>
using namespace std;

int main()
{
    int a = 15, b = 3;
    int quotient, remainder;

    quotient = a / b;
    remainder = a % b;

    cout<<"Quotient is "<<quotient<<endl;
    cout<<"Remainder is "<<remainder;
}

Video explanation