I'm trying to store 10 ints, and im going to attempt to print the 2 highest ints ((No this is not an assignment, I saw someone else trying to complete it I figured id give it a try for practice.PHP Code:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package largestn;
import java.util.*;
/**
*
* @author Xyn
*/
public class Largestn {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int larN1;
int larN2;
int length=10;
System.out.println("Insert 10 numbers and you will recieve the top 2.");
Scanner keyboard = new Scanner(System.in);
int num1 = keyboard.nextInt();
int num2 = keyboard.nextInt();
int num3 = keyboard.nextInt();
int num4 = keyboard.nextInt();
int num5 = keyboard.nextInt();
int num6 = keyboard.nextInt();
int num7 = keyboard.nextInt();
int num8 = keyboard.nextInt();
int num9 = keyboard.nextInt();
int num10 = keyboard.nextInt();
int[] anArray = {num1, num2, num3, num4, num5, num6, num7, num8, num9, num10};
System.out.println(anArray);
}}
I understand im probably taking the long way. But when I get to the system print trying to print anArray I get [I@cf40f5 printed or some other weird letters n numbers... This is telling me that the numbers im inserting are not properly getting stored... Anyways, ill probably have more questions as I go in this thread.
I don't want to be spoon fed, just suggestions on where to go from here. Thanks.
**You can ignore length=10; its irrelevant lol.
**** Nevermind, after further testing of printing individual values of the array they are getting stored properly, just I guess you cannot print the whole array at once..
How can I simplify this? And how do I find the biggest 2 numbers in a array of 10 numbers? I think I could do it but it would be ALOT of if statements.