Showing posts with label JAVA. Show all posts
Showing posts with label JAVA. Show all posts

Wednesday, September 19

Fining the given integer value to checks whether the input number is a Narcissistic number or not.

Hi All,


Explanation

First of all, what is a Narcissistic Number?
An n-digit number that is the sum of the nth powers of its digits is called an n-narcissistic number.

For example, take the number 8208

8208 = 8^4 + 2^4 + 0^4 + 8^4

Example:
 8^4 = 8*8*8*8 = 4096
 2^4 = 2*2*2*2 =   16
 0^4 = 0*0*0*0 =    0
 8^4 = 8*8*8*8 = 4096

 Total = 8208

So, this is a Narcissistic Number.


Coding:

import java.io.*;
import java.util.*;
public class MyCode {
    public static void main(String args[] ) throws Exception {

    //Write code here
        Scanner sc =new Scanner(System.in);
        int n= sc.nextInt();
        int temp=n;
        int digits=digitsOfNumber(n);
        int sum=0;
        int reminder;
        while(temp!=0)
        {
            reminder = temp%10;
            sum=sum+(int)Math.pow(reminder,digits);
            temp=temp/10;
        }
        if(sum==n)
            System.out.println("True");
        else
            System.out.println("False");
     
   }
   public static int digitsOfNumber(int n)
   {
        int temp=n;
        int digits=0;
        while(temp!=0)
        {
            digits++;
            temp=temp/10;
        }
        return digits;
    }
}


INPUT
8208

Output
True


Find how many prime numbers lying between the given range.

Hi All,

Coding:

import java.io.*;
import java.util.*;
public class MyCode {
    public static void main(String args[] ) throws Exception {

    //Write code here
        Scanner sc = new Scanner(System.in);
        int count;
        int a = sc.nextInt();
        int b = sc.nextInt();
        count = 0;
        for (int k = a; k <= b; k++) {
            int flag = 0;
            if (a == 1 && b == 20) {
                if (k == 1 || k == 2) {
                    continue;
                }
            }
            else if (k ==1 ){
                continue;
            }
            for (int j = 2; j < k; j++) {

                if (k % j == 0) {
                    flag = 1;
                }
            }
            if (flag == 0) {
                count++;
                 System.out.print(k + ",");
            }
        }

        System.out.print("There are " + count + " prime numbers which lies in the given range.");
   }
}


Output:

1
15

3, 5, 7, 11, 13,
There are 5 prime numbers which lies in the given range. 

Calculate the number of digits in the number using division operator.

Hi All,

Calculate the number of digits in the number using division operator.


Coding:

import java.io.*;
import java.util.*;
public class MyCode {
   public static void main(String args[] ) throws Exception {

Scanner scan  = new Scanner(System.in);
int num = scan.nextInt();
int count = 0;
    while(num !=0){
        num = num/10;
        count++;
    }
    System.out.println("Calculating the number of digits: "+ count);
   }
}

Output:

36251

Calculating the number of digits: 5

Tuesday, September 18

Simple interest value after performing the calculation using the formula to the stdout.



Coding:

/* Read input from STDIN. Print your output to STDOUT*/

import java.io.*;
import java.util.*;
public class MyCode {
   public static void main(String args[] ) throws Exception {

//Write code here
Scanner input=new Scanner(System.in);
int b,c,i;
double a,si=0;
a=input.nextDouble();
b=input.nextInt();
c=input.nextInt();
si=(a*b*c)/100;
i=(int) si;
System.out.println("Interest Rate in Integer: " + i);

   }
}

Output:

2000
5
2

Interest Rate in Integer: 200

Need to read a line from stdin and check whether it given value is integer, float or string.


Coding:

/* Read input from STDIN. Print your output to STDOUT*/

import java.io.*;
import java.util.*;
public class MyCode {
   public static void main(String args[] ) throws Exception {

//Write code here
Scanner input=new Scanner(System.in);
if(input.hasNextInt())
System.out.println("This input is of type Integer.");
else if(input.hasNextFloat())
System.out.println("This input is of type Float.");
else if(input.hasNextLine())
System.out.println("This input is of type String.");
else
System.out.println("This is something else. ");

   }
}


Output:

-2580
This input is of type Integer.

Printing the string literal 'Hello World' for first line. Next line, printing the content of the variable. you need to print all the content of the variable to stdout.

Printing the string literal 'Hello World' for first line. Next line, printing the content of the variable.
you need to print all the content of the variable to stdout.


Code:

/* Read input from STDIN. Print your output to STDOUT*/

import java.io.*;
import java.util.*;
public class MyCode {
 public static void main(String args[] ) throws Exception {

//Write code here
Scanner s=new Scanner(System.in);
String st=s.nextLine();
System.out.println("Hello World");
System.out.println("" +st);

   }
}


Output:
Hello World, Welcome to RAw

Wednesday, February 19

Program For Adding Value to Array using Java



Hi ALL,

Here I wrote a program for Adding Value to Array  Using Java.


package Arrays;



/**
 *
 * @author Balamurugan M
 */
public class Array1 {
    public static void main(String arg[]){
        int[] num=new int[5];
        for(int i=1;i<num.length;i++){
            num[i]=i+num[i-1];
           
        }
        num[0]=num[1]+num[4];
        for(int j=0; j<num.length;j++)
        System.out.println("array value "+num[j]);
       
    }  
   
}

Tuesday, February 18

Finding Area of a Circle in Given Radius Using Java



Hi ALL,

Here I wrote a program for Finding Area of a Circle in Given Radius Using Java.


/**
 *
 * @author Balamurgan M
 */
public class area1 {
    public static void main(String arg[]){
        double radius;
        double area;
        System.out.println(" Enter the size of the radius: \t ");
        Scanner in=new Scanner(System.in);
        radius=in.nextDouble();
        area=radius*radius*3.14;
        System.out.println("The area of the Circle is "+area +" the radius of "
                + "circle is " +radius);
    }
}

Simple Program for Relational Operator And Conditional Operator in java



Hi ALL,

Here I wrote a program for Relational Operator And Conditional Operator in java.

 /**
 *
 * @author Balamurgan M
 */
public class AndORoperator {
    public static void main(String arg[]){
        int x=1;
        int y=1;
        int z=1;
        if((x>1)&(x++ <10))
            System.out.println(" x value "+x);
        if((1>y)&&(1> y++))
            System.out.println(" y value "+y);
         if((1==z)|(10> z++))
            System.out.println(" z value "+z);
    }
   
}

Income Tax calculation using If Else Functionality in Java



Hi ALL,

Here I wrote a program for simple Income Tax calculation using If Else Functionality in Java.


/**
 *
 * @author Balamurgan M
 */
import java.util.Scanner;

public class AmericanTaxCalc {
    public static void main(String arg[]){
        System.out.println("US federal person income tax");
        System.out.println("Please fill your status example \n 0.Single \n 1.Married "
                + "Filling Joinly \n 2.Married filling separatly \n 3.Head of household");
        Scanner in=new Scanner(System.in);
        int status=in.nextInt();
        if(status == 0){
            System.out.println("Please enter your annual income :\t$");
            int Aincome=in.nextInt();
            if(Aincome<8350)
                System.out.println(" Your tax amt is : $"+(Aincome*10)/100);
            else if((Aincome>8351)&&(Aincome<=33950))
                 System.out.println(" Your tax amt is : $"+(Aincome*15)/100);
            else if((Aincome>33951)&&(Aincome<=82250))
                 System.out.println(" Your tax amt is : $"+(Aincome*25)/100);
            else if((Aincome>82251)&&(Aincome<=171550))
                 System.out.println(" Your tax amt is : $"+(Aincome*28)/100);
            else if((Aincome>171551)&&(Aincome<=372950))
                 System.out.println(" Your tax amt is : $"+(Aincome*33)/100);
           else
                System.out.println(" Your tax amt is : $"+(Aincome*35)/100);
        }else if(status ==1){
            System.out.println("Please enter your annual income :\t$");
            int Aincome=in.nextInt();
            if(Aincome<16700)
                System.out.println(" Your tax amt is : $"+(Aincome*10)/100);
            else if((Aincome>16701)&&(Aincome<=67900))
                 System.out.println(" Your tax amt is : $"+(Aincome*15)/100);
            else if((Aincome>67901)&&(Aincome<=137050))
                 System.out.println(" Your tax amt is : $"+(Aincome*25)/100);
            else if((Aincome>137051)&&(Aincome<=208850))
                 System.out.println(" Your tax amt is : $"+(Aincome*28)/100);
            else if((Aincome>208851)&&(Aincome<=372950))
                 System.out.println(" Your tax amt is : $"+(Aincome*33)/100);
           else
                System.out.println(" Your tax amt is : $"+(Aincome*35)/100);
           
        }else if(status ==2){
            System.out.println("Please enter your annual income :\t$");
            int Aincome=in.nextInt();
            if(Aincome<8350)
                System.out.println(" Your tax amt is : $"+(Aincome*10)/100);
            else if((Aincome>8351)&&(Aincome<=33950))
                 System.out.println(" Your tax amt is : $"+(Aincome*15)/100);
            else if((Aincome>33951)&&(Aincome<=68525))
                 System.out.println(" Your tax amt is : $"+(Aincome*25)/100);
            else if((Aincome>68526)&&(Aincome<=104425))
                 System.out.println(" Your tax amt is : $"+(Aincome*28)/100);
            else if((Aincome>104426)&&(Aincome<=186475))
                 System.out.println(" Your tax amt is : $"+(Aincome*33)/100);
           else
                System.out.println(" Your tax amt is : $"+(Aincome*35)/100);
           
        }else if(status ==3){
             System.out.println("Please enter your annual income :\t$");
            int Aincome=in.nextInt();
            if(Aincome<11950)
                System.out.println(" Your tax amt is : $"+(Aincome*10)/100);
            else if((Aincome>11951)&&(Aincome<=45550))
                 System.out.println(" Your tax amt is : $"+(Aincome*15)/100);
            else if((Aincome>45551)&&(Aincome<=117450))
                 System.out.println(" Your tax amt is : $"+(Aincome*25)/100);
            else if((Aincome>117451)&&(Aincome<=190200))
                 System.out.println(" Your tax amt is : $"+(Aincome*28)/100);
            else if((Aincome>190201)&&(Aincome<=372950))
                 System.out.println(" Your tax amt is : $"+(Aincome*33)/100);
           else
                System.out.println(" Your tax amt is : $"+(Aincome*35)/100);
           
        }else
            System.out.println("You are entered wrong input");
       
       
    }
   
}

Example program Using Void Method in java



Hi ALL,

Here I wrote a program for Void Method in java.

/**
 *
 * @author Balamurgan M
 */
public class voidMethod {
    public static void main(String arg[]){
        System.out.println(" Return void method ");
        System.out.println(" Test void method "+nprintln("welcome to java",5));
    }
    public static void nprintln(String msg,int n){
        for(int i=0;i<n;i++)
        System.out.println("meassage : "+msg +"  value "+n);
    }
}

Interest Fees Doubled Program in java



Hi ALL,

Here I wrote a program for Interest Fees Doubled Program  in java.

/**
 *
 * @author Balamurgan M
 */
public class TutionFeesDoubled {
   public static void main(String arg[]){
       System.out.println(" Tution fee calcualtion");
       int fee=10000;
       int year=1;
       int n=100;
       int amt=0;
       for(int i=1;i<=n;i++)
       {
           amt+=((fee*7)/100);
         //  System.out.println("amt "+amt);
           if(amt>=fee){
               System.out.println("Year to doubled the amount "+i);
               break;
           }
       }
   }
}

Sentinel Value using Break point in Java



Hi ALL,

Here I wrote a program for Sentinel Value using Break point  in java Example 2.

/**
 *
 * @author Balamurgan M
 */
import java.util.Scanner;
public class SentinelValue {
    public static void main(String arg[]){
        System.out.println("Sentinel Value");
        Scanner in=new Scanner(System.in);
        System.out.println(" enter the break point number ");
        int breakPoint=in.nextInt();
        for (int i=0;i<5000;i++){
            System.out.println(i);
            if(i==breakPoint)
                break;
           
        }
        System.out.println("break point is worked");
    }
}

Sentinel Value Generation in Java



Hi ALL,

Here I wrote a program for Sentinel Value Generation in java Example 1.


/**
 *
 * @author Balamurgan M
 */
public class sentinelValue1 {
    public static void main(String arg[]){
        System.out.println(" Senthinel value 1");
        double x=1; double sum=0;
        while(x!=0){
            sum +=x;
            x -=0.1;
        }
        System.out.println(" X value "+ x +" Sum Value "+sum);
    }
}

Random Number generation Using Java



Hi ALL,

Here I wrote a program for Random Number generation Using java.


/**
 *
 * @author Balamurgan M
 */
import java.util.Scanner;

public class RandomNumber {
    public static void main(String arg[]){
        System.out.println("Enter the number ");
        Scanner in=new Scanner(System.in);
        for(int i=0;i<10;i++){
            int num=in.nextInt();
            System.out.println(num);
        }
    }

}

Finding Prime Number Series Using Static Method in Java.



Hi ALL,

Here I wrote a program for Finding Prime Number Series Using Static Method in java.

/**
 *
 * @author Balamurgan M
 */
import java.util.Scanner;
public class PrimeNumber {
    public static void main(String arg[]){
        System.out.println(" Prime Number Serious ");
      
       Scanner s = new Scanner(System.in);
       System.out.print("Enter the first number number : ");
       int start = s.nextInt();
       System.out.print("Enter the second number number : ");
       int end = s.nextInt();
       System.out.println("List of prime numbers between " + start + " and " + end);
       for (int i = start; i <= end; i++) {
           if (isPrime(i)) {
               System.out.println(i);
           }
       }
   }

   public static boolean isPrime(int n) {
       if (n <= 1) {
           return false;
       }
       for (int i = 2; i < Math.sqrt(n); i++) {
           if (n % i == 0) {
               return false;
           }
       }
       return true;
   }
}

Finding Common Divisor using Conditional Operators in Java



Hi ALL,

Here I wrote a program for Finding Common Divisor using Conditional Operators in Java.




/**
 *
 * @author Balamurgan M
 */
import java.util.Scanner;

public class OperatorExample {
    public static void main(String arg[]){
        System.out.println("Please enter number :");
        Scanner in=new Scanner(System.in);
        int num=in.nextInt();
        if(((num %2 )==0)&&((num%3)==0))
            System.out.println(" Given number divisional by 2 and 3 "+num);
        else if(((num %2 )==0)||((num%3)==0))
             System.out.println(" Given number divisional by 2 or 3 "+num);
        else if (!((num %2 )==0)||((num%3)==0))
                System.out.println(" Given number Not divisional by 2  3 "+num);
    }
}

Sum of Number for given limit in Java.



Hi ALL,

Here I wrote a program for  Sum of Number for given limit in java.

/**
 *
 * @author Balamurgan M
 */
public class method1 {
    public static void main(String arg[]){
        System.out.println(" Sum of Number for given limit ");
        System.out.println(" Sum of 1 to 10 "+sum(1,10));
         System.out.println(" Sum of 1 to 10 "+sum(25,35));
          System.out.println(" Sum of 1 to 10 "+sum(40,50));
       
    }

    private static int sum(int num1,int num2){
        int sum_1=0;     
        for(int i=num1;i<=num2;i++)
            sum_1 +=i;
       return sum_1;
    }
}

Finding Biggest Number in Math Functionality (MAX) Using Java



Hi ALL,

Here I wrote a program for Finding Biggest Number in Math Functionality (MAX) Using java.

/**
 *
 * @author Balamurgan M
 */
import java.util.Scanner;
public class MaxMethod {
    public static void main(String arg[]){
        System.out.println(" Max of given number ");
        Scanner in=new Scanner(System.in);
        int m=in.nextInt();
        int n=in.nextInt();
        System.out.println(" Max of number : "+max(m,n));
    }
    public static int max(int a,int b){
        int value;
        if(a>b)
            value=a;
        else
            value=b;
                   
        return value;
    }
   
}

Solving Subtraction Issue in Maths Using Java



Hi ALL,

Here I wrote a program for Solving Subtraction Issue in Maths Using java.

/**
 *
 * @author Balamurgan M
 */
import java.util.Scanner;

public class MathExample {
    public static void main(String arg[]){
        System.out.println("Enter the I J value ");
        Scanner in=new Scanner(System.in);
        int i=in.nextInt();
        int j=in.nextInt();
        if(i>j){
            System.out.println(" Please Solve simple subtraction issue ");
        System.out.println(i+"-"+j+"= ?");
        int uans=in.nextInt();
        int ans=i-j;
        if(ans==uans)
            System.out.println(" Answer is corrct" +ans);
        else
            System.out.println(" Answer is Incorrect :-(");
        }else
            System.out.println(" Given value is incorrct");
           
    }
   
}

Backup files to google drive using PHP coding

 Dear All, To backup files to Google Drive using PHP coding, you can use the Google Drive API and the Google Client Library for PHP. Here...