0% found this document useful (0 votes)
30 views

MidPoint Array

This document describes a Java program that takes in a number of points from the user, stores them in an array, calculates the midpoint between each set of points in the array, stores the midpoints in a second array, and displays the midpoints. The program first prompts the user to enter a number of points, initializes an array to store the points, and uses a for loop to read in each point and store it in the array. It then initializes a second array to store the midpoints, calculates and stores each midpoint by taking the average of two points from the first array in a for loop, and finally outputs each midpoint in another for loop.

Uploaded by

Anubhav Dutta
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

MidPoint Array

This document describes a Java program that takes in a number of points from the user, stores them in an array, calculates the midpoint between each set of points in the array, stores the midpoints in a second array, and displays the midpoints. The program first prompts the user to enter a number of points, initializes an array to store the points, and uses a for loop to read in each point and store it in the array. It then initializes a second array to store the midpoints, calculates and stores each midpoint by taking the average of two points from the first array in a for loop, and finally outputs each midpoint in another for loop.

Uploaded by

Anubhav Dutta
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Class Object_Array - CS_ISC 1/1

1 import java.util.*;
2 class Object_Array
3 {
4 public static void main(String args[])
5 {
6 Scanner in=new Scanner(System.in);
7 System.out.print("Enter number of points:");
8 int x=in.nextInt();
9 MidPoint[] mp=new MidPoint[x];
10 for(int i=0;i<x;i++)
11 {
12 mp[i]=new MidPoint();
13 System.out.print("Point"+(i+1)+":");
14 mp[i].readPoint();
15 }
16 MidPoint[] mid=new MidPoint[x/2];
17 for(int i=0;i<x/2;i++)
18 {
19 mid[i]=new MidPoint();
20 int l=mp.length;
21 mid[i]=mid[i].mPoint(mp[i],mp[l-i-1]);
22 }
23 for(int i=0;i<x/2;i++)
24 {
25 System.out.println("MidPoint no.:"+(i+1));
26 mid[i].display();
27 }
28 }
29 }

23 Jul, 2021 10:20:56 AM

You might also like