Hi,
I'm using the following code that takes input from the user for votes that are counted on a scale of 1-7, the programme terminates taking input once 0 is entered.
import java.io.*; import java.util.*; public class Arrays1 { /** * @param args */ public static void main(String[] args) throws IOException{ Scanner a = new Scanner(new File("C:\\temp_Name\\votes.txt")); int maxIndx = -1; String name[] = new String[8]; name[0] = ""; while(a.hasNext()){ maxIndx++; name[maxIndx] = a.next(); } a.close(); int results[] = new int[name.length]; Scanner kbb = new Scanner(System.in); System.out.println("Enter your vote number, 1. Victor Taylor 2. Denise Duncan 3. Kamal Ramdhan 4. Michael Ali 5. Anisa Shah 6. Carol Khan 7. Gary Owen"); int v = kbb.nextInt(); while((v !=0) && (v<=7)){ { Scanner kb = new Scanner(System.in); System.out.println("Enter your vote number, 1. Victor Taylor 2. Denise Duncan 3. Kamal Ramdhan 4. Michael Ali 5. Anisa Shah 6. Carol Khan 7. Gary Owen"); v = kb.nextInt(); if(v==1){ results[0] = results[0]+1; } if(v==2){ results[1] = results[1]+1; } if(v==3){ results[2] = results[2]+1; } if(v==4){ results[3] = results[3]+1; } if(v==5){ results[4] = results[4]+1; } if(v==6){ results[5] = results[5]+1; } if(v==7){ results[6] = results[6]+1; } } FileWriter f = new FileWriter("C:\\temp_name\\results.txt"); PrintWriter p = new PrintWriter(f); p.print(results); p.close(); f.close(); } } }
When I compile this program, and check the file results.txt it only says '[I@14318bb', I want it to list the count of each number as well as a count of all the invalid votes e.g. any vote that was above 7 and/or 0.
Help please!