Hi I solved my homework in C++ then copied the code to Java, fixed it up but it wont run correctly. The error seems to be in my for loop because it would work the first time, then i would get an error in my Eclipse compiler. By the way my code works in C++.
import java.util.*; public class ExtraArrayQuestionsJava { public static void main(String[] args) { Scanner input= new Scanner (System.in); //Question #1 System.out.println("Question #1: "); String name; int freq; int f1=0,f2=0,f3=0,f4=0,f5=0,f6=0; System.out.println("Enter city Name then the # of Accidents, or 'a' to end: "); name=input.nextLine(); while(!(name.equals("a"))){ freq=input.nextInt(); if(freq>=0 && freq<=99){ f1++; } else if(freq>=100 && freq<=199){ f2++; } else if(freq>=200 && freq<=299){ f3++; } else if (freq>=300 && freq<=399){ f4++; } else if (freq>=400 && freq<=499){ f5++; } else{ f6++; } System.out.println("Enter city Name then the # of Accidents, or a to end: "); name=input.nextLine(); } System.out.println("RESULTS:"); System.out.println("Frequencies Between 0-99 : ");for(int k=0;k<f1;k++)System.out.print("|"); System.out.println(); System.out.println("Frequencies Between 100-299: ");for(int k=0;k<f2;k++)System.out.print("|"); System.out.println(); System.out.println("Frequencies Between 200-299: ");for(int k=0;k<f3;k++)System.out.print("|"); System.out.println(); System.out.println("Frequencies Between 300-399: ");for(int k=0;k<f4;k++)System.out.print("|"); System.out.println(); System.out.println("Frequencies Between 400-499: ");for(int k=0;k<f5;k++)System.out.print("|"); System.out.println(); System.out.println("Frequencies Between 500>= : ");for(int k=0;k<f6;k++)System.out.print("|"); System.out.println(); }