Tuesday, 10 October 2017

java program calculate sum of element of number


import java.util.*;
public class numSums
{
 public static void main(String args[])
{
  Scanner p= new Scanner(System.in);
   int num,sum=0;
    System.out.println("Enter any number please :");
    num=p.nextInt();
    while(num!=0)
{
       sum+=num%10;
       num/=10;
}
       System.out.println("The sum of all the elements of number is :"+sum);
}}

      

java function program take personal information


import java.util.*;
class person
{
  Scanner p = new Scanner(System.in);
  String name,address,gender;
 int age,id;
  String name()
{
   System.out.println("Enter the name of person ");
  name=p.nextLine();
  return name;
}
 int age()
{
   System.out.println("Enter the age of person ");
  age=p.nextInt();
 return age;
}
 String gender()
{
   System.out.println("Enter the gerder of person ");
  gender=p.nextLine();
 return gender;
}
int id()
{
   System.out.println("Enter the id of person ");
  id=p.nextInt();
 return id;
}
 String address()
{
   System.out.println("Enter the address of person ");
  address=p.nextLine();
 return address;
}}
public class personInformation
{
  public static void main(String args[])
{
 Scanner p = new Scanner(System.in);
 System.out.println("Enter the number of repitition :");
  int n=p.nextInt();
 person bilal = new person();
for (int i=1;i<=n;i++)
{
 
 System.out.println("Your name is  :"+bilal.name());
  System.out.println("Your age is  :"+bilal.age());
System.out.println("Your gender is  :"+bilal.gender());
System.out.println("Your id is  :"+bilal.id());
System.out.println("Your address is  :"+bilal.address());
}}} 

java calculator using functions


import java.util.*;

 class math
 {
     double num2,num1;
     double sum()
     {
          Scanner p = new Scanner(System.in);
         System.out.println("Enter the value of number 1 :");
          num1=p.nextDouble();
          System.out.println("Enter the valur of number 2 :");
          num2 = p.nextDouble();
           return num1+num2;
     }
      double subtraction()
     {
          Scanner p = new Scanner(System.in);
         System.out.println("Enter the value of number 1 :");
          num1=p.nextDouble();
          System.out.println("Enter the valur of number 2 :");
          num2 = p.nextDouble();
           return num1-num2;  
     }
    double product()
     {
          Scanner p = new Scanner(System.in);
         System.out.println("Enter the value of number 1 :");
          num1=p.nextDouble();
          System.out.println("Enter the valur of number 2 :");
          num2 = p.nextDouble();
           return num1*num2;
     }
     double division()
     {
          Scanner p = new Scanner(System.in);
         System.out.println("Enter the value of number 1 :");
          num1=p.nextDouble();
          System.out.println("Enter the valur of number 2 :");
          num2 = p.nextDouble();
           return num1+num2;
     }
             
 }
public class CalculatoreFunction
{
    public static void main(String args[])
    {   Scanner p= new Scanner(System.in);
        math as = new math(); 
      byte num;
       System.out.println("Enter 1 for addition \n Enter 2 for Subtraction \n Enter 3 for  multiplication \n Enter 4 for division :");
           num=p.nextByte();
     switch(num)
{
        
       case 1:     
  System.out.println("The result is  :"+as.sum());
      break;
     case 2:
     System.out.println("The result is :"+as.subtraction());
   break;
      case 3:
      System.out.println("The result is :"+as.product());
      break;
      case 4:
      System.out.println("The result is  :"+as.product());
 break;
       default:
        System.out.println("You enter wrong entery :");
}   
}
}

java function calculate division of number


class division
{
     double num1,num2;
    double divi()
{
     num1=90;
     num2=21;
      return num1/num2;
}}
   public class function3
  {
     public static void main(String args[])
{
       division p = new division();
     System.out.println("The product is ="+p.divi());
}}

java function calculate product


class product
{
     int num1,num2;
    int pro()
{
     num1=9;
     num2=2;
      return num1*num2;
}}
   public class function2
  {
     public static void main(String args[])
{
       product p = new product();
     System.out.println("The product is ="+p.pro());
}}

java function subtraction of two numbers


class Subtraction
{
     int num1,num2;
    int sub()
{
     num1=120;
     num2=30;
      return num1-num2;
}}
   public class function1
  {
     public static void main(String args[])
{
       Subtraction p = new Subtraction();
     System.out.println("The Subtraction is ="+p.sub());
}}

java program fin max and min number


import java.util.*;
 public class maxMin
{
 public static void main(String args[])
{
 Scanner p= new Scanner(System.in);
 System.out.println("Enter the value of a");
 int a=p.nextInt();
  System.out.println("Enter the value of b");
  int b=p.nextInt();
  if(a>b)
  System.out.println("a is greater then b");
 else if(a<b)
  System.out.println("b is greater then a");
  else
  System.out.println("Both are equal ");
}}

Java program take persnol infromation and print on screen


import java.util.*;
public class personInformation
{
  public static void main(String args[])
 {
      Scanner p = new Scanner(System.in);
       String name,add,gender;
        int id,age;
        System.out.println("Enter the name of person :");
         name=p.nextLine();
        System.out.println("Enter the gender of person :");
         gender=p.nextLine();
        System.out.println("Enter the age of person :");
         age=p.nextInt();
          System.out.println("Enter the id of person :");
         id=p.nextInt();
          p.nextLine();
         System.out.println("Enter the address of person :");
         add=p.nextLine();
          System.out.printf("Your name is  %s",name);
              System.out.printf("\nYour age is  %d",age);
              System.out.printf("\nYour id is  %d",id);
              System.out.printf("\nYour gender is  %s",gender);
              System.out.printf("\nYour address is  %s",add);
}}

using loop java calculator


mport java.util.*;
 public class loopCalculator
{
  public static void main(String args[])
{
      Scanner p = new Scanner(System.in);
      double num1,num2,res=0;
          int n;
 for(int i=1;i!=-1;i++)
{
   
  System.out.println("\nEnter 1 to calculate sum 2 for subtraction 3 for product 4 for division");
         n=p.nextInt();
      switch(n)
{
       case 1:
         System.out.println("Ente two numbers ");
            num1=p.nextDouble();
           num2=p.nextDouble();
           res=num1+num2;
         System.out.printf("The sum of two numbers is :%f",res);
       break;
      case 2:
                 System.out.println("Ente two numbers ");
            num1=p.nextDouble();
           num2=p.nextDouble();
           res=num1-num2;
         System.out.printf("The subtraction of two numbers is :%f",res);
       break;
            case 3:
                      System.out.println("Ente two numbers ");
            num1=p.nextDouble();
           num2=p.nextDouble();
           res=num1*num2;
         System.out.printf("The product of two numbers is :%f",res);
       break;
case 4:
                     System.out.println("Ente two numbers ");
            num1=p.nextDouble();
           num2=p.nextDouble();
            res=num1/num2;
         System.out.printf("The division of two numbers is :%d",res);
       break;
 default:
    System.out.println("You Enter a wrong number");
}}}}
      

java program calculate sum of element of number


import java.util.*;
public class numSums
{
 public static void main(String args[])
{
  Scanner p= new Scanner(System.in);
   int num,sum=0;
    System.out.println("Enter any number please :");
    num=p.nextInt();
    while(num!=0)
{
       sum+=num%10;
       num/=10;
}
       System.out.println("The sum of all the elements of number is :"+sum);
}}

      

Java program calculate product of three number taking from user


import java.util.*;
 public class product
{
  public static void main(String args[])
{
  Scanner p= new Scanner(System.in);
  int a,b,c,pro;
 System.out.println("Enter three number please :");
 a=p.nextInt();
 b=p.nextInt();
 c=p.nextInt();
 pro=a*b*c;
  System.out.printf("The product of three numbers is =%d",pro);
  }}

Java program print even number table


import java.util.*;
public class EvenTabble
{
 public static void main(String args[])
{
  Scanner p= new Scanner(System.in);
 int num,limit;
  System.out.println("Enter the table number please :");
  num=p.nextInt();
 System.out.println("Enter the limit of table please ");
  limit=p.nextInt();
 for(int i=1;i<=limit;i++)
{
 if(i%2==0)
 System.out.println(num+" x "+i+" = "+(num*i));
}}}

Java program print odd number table


import java.util.*;
public class oddTabble
{
 public static void main(String args[])
{
  Scanner p= new Scanner(System.in);
 int num,limit;
  System.out.println("Enter the table number please :");
  num=p.nextInt();
 System.out.println("Enter the limit of table please ");
  limit=p.nextInt();
 for(int i=1;i<=limit;i++)
{
 if(i%2==1)
 System.out.println(num+" x "+i+" = "+(num*i));
}}}