Sunday, January 17, 2021

Converting Values From Double To Int Using Array

 
In this program, 10 double values will be stored in a single array A and truncate fractional part of array A and store integer part in array B

import java.util.*;
class Arr
{
  
    Scanner sc=new Scanner(System.in);
    int B[]=new int[10];
    double A[]=new double[10];
    int i;
    void take()
    {
        for(i=0;i<10;i++)
        {
            System.out.print("\nDouble Value:");
            A[i]=sc.nextDouble();
        }
            System.out.print("\nDouble values as follows:");
            for(i=0;i<10;i++)
        {
            System.out.print(" "+A[i]);
           
        }
         for(i=0;i<10;i++)
        {
            B[i]=(int)A[i];
           
        }
            System.out.print("\nInteger values as follows:");
            for(i=0;i<10;i++)
        {
            System.out.print(" "+B[i]);
           
        }        
        }
public static void main(String args[])
{
Arr ob=new Arr();
ob.take();
}
    }

No comments:

Post a Comment

Subscribe via email

Enter your email address:

Delivered by FeedBurner