KnowledgeBoat Logo
LoginJOIN NOW

Computer Applications

Write a program to accept 10 different decimal numbers (double data type) in a Single Dimensional Array (say, A). Truncate the fractional part of each number of the array A and store their integer part in another array (say, B).

Java

Java Arrays

54 Likes

Answer

import java.util.Scanner;

public class KboatSDATruncate
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        double a[] = new double[10];
        int b[] = new int[10];
        
        System.out.println("Enter 10 decimal numbers");
        for (int i = 0; i < a.length; i++) {
            a[i] = in.nextDouble();
            b[i] = (int)a[i];
        }
        
        System.out.println("Truncated numbers");
        for (int i = 0; i < b.length; i++) {
            System.out.print(b[i] + ", ");
        }
    }
}

Variable Description Table

Program Explanation

Output

BlueJ output of Write a program to accept 10 different decimal numbers (double data type) in a Single Dimensional Array (say, A). Truncate the fractional part of each number of the array A and store their integer part in another array (say, B).

Answered By

13 Likes


Related Questions