← All resources

Write a program to input an array containing decimal point numbers and round them off to the nearest integer.

import java.util.*;
public class Array_Round
{
    public static void main()
    {
        Scanner sc = new Scanner(System.in);
        double n[] = new double[10];
        int i, x;
        System.out.println("Enter 10 numbers with decimal points:");
        for(i=0;i<10;i++)
        {
            n[i] = sc.nextDouble();
        }
        System.out.println("Rounded values are:");
        for(i=0;i<10;i++)
        {
            x = (int)n[i];
            if(n[i]-x>=0.5)
            x = x+1;
            System.out.println(x);
        }
    }
}