I have a 2D array and the elements are listed as follows:
outlook temperature humidity windy gooutside
sunny hot high false n
overcast hot high false y
....
I need to put these values into a HashMap, where the elements of the first row are the keys and the elements from row 1 to n-1 are the values. What would be the best way to make sure the key and values are matched correctly?
I am having trouble putting an int value into an array. The error code I get at compile time is this: "error: array required, but int found". The following is snippets of my array initialization and the line producing the error.
int[] fitness = new int[POPULATION_SIZE]; int fitness = 100;
Next, the line where the problem occurs. In this code "i" is an int variable that represents a place in the array fitness (this part of the code is within a for loop).
I have one doubt.In HashMap if keys contains 1,2,3,4 and values are a,b,c,d we can get values using get(key) method like 1 will A,2 will return B and so on. Can we get the keys from values like A will get 1 and also if in key if there is a String like 1,2,3,Z and value is A,B,C,7 Z should get me 7. Here I am not using any generics.
Currently working on a simple file processing problem, namely, reorder a set of strings (called bid phrases) in terms of the score value associated to them in descending order.
Here is my HashMap and a method for listing all the keys in it
HashMap<String, String> exampleOne = new HashMap<String, String>(); public void allKeys() { int i; i =0; for (String name: exampleOne.keySet())
[Code]....
Now I want to return all values that associated with one key. How do I do this? Or is it possible to other way round? I mean return All keys associated with a value?
I am working on the Kevin Bacon - 6 degrees of bacon problem. I want to take my Array List and use the index and Values that I have saved in it as the Key and Value of a Hashmap. Below is my code.
HashMap<Integer, ArrayList<String>> actors = new HashMap<Integer, ArrayList<String>>(); ArrayList array = new ArrayList(); try (BufferedReader br = new BufferedReader( new FileReader("actors.txt"));)
[code]...
saving each one in it's own spot. I want to use the index of each one as the key to find it in the Hashmap....
I have to shuffle a deck (array) of 52 integers but I started with 3 for testing if it was an even shuffle and it will place the same integer in more than one spot in the random array. I'm not sure what I'm doing wrong...
import java.util.Random; public class shuffleDeck { public static void main(String[] args) { int[] Deck = new int[3]; for (int i=0; i<3; i++) {
I need assigning the selected hashmap values into a list and to display the values in a jsf page. The user will select certificates and will be stored in the below list:
private List<String> selectedCertificates = new ArrayList<String>();
The selectedCertificates will have the values ("AA","BB"). Now I will be passing the list into a hashmap in order to get the names and to display them on the jsf page.
Now my issue is that is how to display all the values of the CertificatesNames.get(key1) in the jsf page as I tried to do the below and it printed all the values when I used the #{mybean.beans} using the :
List beans = new ArrayList(CertificatesNames.values());
I have an assignment on sorting, i kno i can get the sorting down but im having an issue with inputing the 512 ints in a file into an array. the instructor provided us with a file with 4 equal sets of ints. i tried to make my array of size [scan.nextInt()] and it cuts off the last 21 ints. and skips the first int. how can i get all of the integers in the text file into my array? this is what i have so far. if i hard code the array to size 50000 and then try to print the array it compiles but errors out when running it.
System.out.println("Please Enter text file in this format, XXXXX.txt :"); String file =fileName.nextLine(); Scanner scan = new Scanner(new File(file)); int [] data = new int[scan.nextInt()]; <-------here it skips first int int count= data.length; for (int i=0; i<data.length-1;i++) { data[i]=scan.nextInt(); } System.out.print(Arrays.toString(data));
rst 4 ints in output are: 501, 257, 390, 478...., supposed to be 492,501,390....and last ints are: ....88, 83, 79, 0 and supposed to be :88 83 79 77 76 72 71 71 66 57 56 48 48 41 33 30 23 23 18 17 15 13 9....it replace last ints with 0. why ? and how do i fix this. attached it the text file
I have a file called statecapitals.txt that is read in, I want to store it in either a 2d array or hashmap and select a random state then Ask the user for the name of the capital. Then I want to Let them know if they are correct or not and have a choice to play as many times as they like. When they no longer want to play,I want to let them know how many they got correct and how many incorrect. I am not sure which would be better a hash map or 2d array and dont know where to start with each.
here is what the text file looks like:
Alabama - Montgomery Alaska - Juneau Arizona - Phoenix Arkansas - Little Rock California - Sacramento Colorado - Denver
Write a method that returns a new array by eliminating the duplicate values in the array using the following method header: public static int[] eliminateDuplicates(int[] list). The thing is that I found the working solution that is written below, but how it works. How to eliminateDuplicates method done with flag and flag2.
Here is the code:
Java Code:
import java.util.Scanner; public class Exercise06_15 { public static void main(String[] args) { java.util.Scanner input = new java.util.Scanner(System.in); int[] numbers = new int[10]; System.out.println("Enter ten numbers: ");
filling out a Random array: An Array of Specific Length Filled with Random Numbers This time what I need to do is take the elements from this Random array and assign them to a new Byte array:
for(int i = 0; i < limit-10; i++) { Random dice = new Random(); int randomIndex = dice.nextInt(array.length); if (array[randomIndex] < 128) { System.out.print(array[randomIndex] + " "); } else if (array[randomIndex] >= 128) { System.out.print(array[i] + " "); } } byte[] noteValues = new byte[]
{ 64, 69, 72, 71, 64, 71, 74, 72, 76, 68, 76 }; //This is the byte array filled manually!
I've tried amending the manual input to fit in with the Random array, as follows:
byte[] noteValues = new byte[] { array[randomIndex] };
In this case, however, the Byte array can't interpret the int values. Also, if the Byte array is outside the 'for' loop, array[randomIndex] cannot be resolved.
I'm trying to read user input from the terminal and separate the input into separate arrays depending on if the user input is an integer, scanner, or a string. The terminal should keep asking the user for input until the user types "quit".
import java.util.*; public class arrayScanner { public static void main(String[] args) { ArrayList<Integer> intList = new ArrayList<Integer>(); ArrayList<Double> doubleList = new ArrayList<Double>(); ArrayList<String> otherList = new ArrayList<String>();
I am trying to make a code that takes a list and puts the list in sorted order (least to greatest).
public class SortedIntList { static final int capacity = 10; private int [] data; private boolean unique; private int size; public SortedIntList(){ size =0; data = new int [10];
[Code] ....
Here what the code produces.
Testing SortedIntList() error when adding these values to list: 4 6 4 list should = [4, 4, 6] actual list = [4, 6, 4] was working properly prior to adding last value of 4
I have two classes - One is Read.java and the other is Display.java
Read.java looks like this
public static void main(String[]args){ File file = new File("test.txt"); try{ FileReader fr = new FileReader(file); BufferedReader br = new BufferedReader(fr);
[Code] ....
Display.java looks like this:
public class Display extends JFrame { private JComboBox comboBox; private JPanel contentPane;
/** * Launch the application. */ public static void main(String[] args) { //method call to access other class
[Code] ....
Instead of having it so it displays the id's to the console,is there a way I can set it straight up to the combo box?
I'm trying to isolate specific values produced from that array at random. For example, if I were to have an array whose starting inputs are 5 & 10, the output is 5, 10, 15, 25, 40, 65 (the array stops before exceeding 100). Following this, I would generate 6 random numbers from this array (if the array is longer or shorter an equal number of random values from those arrays are generated) allowing for possible repetition of numbers.
So far, I have imported the Random utility and placed the following code below yesterdays code:
System.out.println(); for(int i = 0; i < limit; i++) { if (array[i] < 100) { System.out.println(); System.out.println("Rand. no. from array"); Random dice = new Random(); System.out.print(dice.nextInt(array[i])); //Call the Fibonacci array & generate rando numbers from it!! } }
Using the above (5, 10) array as an example, the output seems to generate 6 results for each position, but the random element is localised to each number, rather than the whole array. So, at position one we have number 5 and 'any' number between 1 & 5 is generated, rather than any 'specific' number from the 'whole' array. At the second position we have 10 and the printout will give the 2nd random number as anything between 1 & 10, and so on for the rest of the array. Ideally, I'd be looking for something like: 5, 40, 5, 65, 40, 15.
And as it is now, the values are not being passed into the shapeArray array. If I "hard code" two shapes into the array in this class, everything works fine later on, but I do not manage to pass values into the array from the createShape() method. I tried several approaches, nothing works.
In the "Humidity(%)" row, they come out fine, but when I do this, they come out as 0, which I think would explain why my heat indices are consistently lower than the temperature when the temperature is over 80.
My code:
import java.util.Scanner; import java.io.File; import java.io.IOException; public class HeatIndex { public static void main(String[] args) throws IOException { System.out.printf("%70s", "Heat Index: Key West, Florida");
how to replace the values in my array with the results of my function factorial.
public static void main(String[] args) { //this is my main function: int[] array = {5,4,3,2,1}; int i = 0; System.out.print("results: "); for (i = 0; i < array.length; i++){ System.out.print(factorial(array[i]));
[code]....
So, what I'm trying to do is change the contents of the array "array" into their factorial value. So, they should be replaced with {120,24,6,2,1}. then add those using linear sum but that's a different story.
I am new to Android. I have byte array of size 10. I am passing the Decimal values (131 - 140) to byte array. But while printing I get Negative (-) values with decreasing order .
How can I get same value as positive values?
Or How can I store positive value e.g. 131 as byte array element.
Please not my requirement is array must be ByteArray only