Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6876651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:30:14+00:00 2026-05-27T04:30:14+00:00

I’m working on an assignment for my Intro to Java course and I’m currently

  • 0

I’m working on an assignment for my Intro to Java course and I’m currently stuck trying to sort an array of integers.

I get the values from a point object array, p, and pass them to an int array of the same size, pSize. All I need is the point object’s value of x to be typecast to int and get the array sorted. However, that is not occuring. Here is the code:

import java.util.*;
import java.awt.*;

public class doCheckWin {
// Class Fields
private Point[] p;
private static int pSize;

/*
        Class Constructor.
        Creates an array of point objects that holds the user's
        location of pieces.
*/
public doCheckWin(Point[] p) {
        this.p = p;
        pSize = p.length;
}

public void checkHorizontal() {
        int[] col = new int[pSize];
        for(int i=0; i<p.length; i++) {
            col[i] = (int)p[i].getX();
        }
        Arrays.sort(col);
        System.out.println(Arrays.toString(col));
    } 
}

Here’s the method from another classthat passes the point object:

public void checkWin(Point[] p) {
    doCheckWin dcw = new doCheckWin(p);
    dcw.checkHorizontal();
}

When I print the array to screen, the values are ints…using getX changes them to double but when typecasting to int it’s not working…

The problem is:

  1. Typecasting the value of x (ie: 10.0) to an integer does not work. When printing the results out on the screen I still get 10.0.
  2. Arrays.sort(col) is not sorting the array.

Sample Output of What I’m Getting

10.0
13.0
12.0
11.0
3.0

What I Want

3
10
11
12
13

Edit: Here’s the code used to print out the array:

Arrays.sort(col);
for(int i=0; i<col.length; i++) {
    System.out.println(col[i]);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:30:15+00:00Added an answer on May 27, 2026 at 4:30 am

    What is the point of your Point object (no pun intended)?

    What is the contents of p[]? Is it an array of Point objects like you said? If so, why are you creating a point object from a point object?

    It looks like you want to do something like so:

    int[] col = new int[pSize];
    for (int i = 0; i < p.length; i++) {
        col[i] = (int)p[i].getX();
    }
    Arrays.sort(col);
    System.out.println(Arrays.toString(col));
    

    That seem to work for me.

    Here is an example:

    int pSize = 5;
    Point[] p = new Point[pSize];
    
    Random z = new Random();
    for (int i = 0; i < p.length; i++) {
        p[i] = new Point(i+z.nextInt(5), i);
    }
    
    System.out.println(Arrays.toString(p));
    
    int[] col = new int[pSize];
    for (int i = 0; i < p.length; i++) {
        col[i] = (int)p[i].getX();
    }
    Arrays.sort(col);
    System.out.println(Arrays.toString(col));
    

    Which gives:

    [java.awt.Point[x=3,y=0], java.awt.Point[x=3,y=1], java.awt.Point[x=6,y=2], java.awt.Point[x=3,y=3], java.awt.Point[x=4,y=4]]
    [3, 3, 6, 3, 4]
    [3, 3, 3, 4, 6]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently running into a problem where an element is coming back from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.