Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Weird Compiling Error.

  1. #1
    Member
    Join Date
    Sep 2013
    Posts
    41
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Weird Compiling Error.

    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();
    }


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    6,104
    My Mood
    Mellow
    Thanks
    244
    Thanked 755 Times in 741 Posts

    Default Re: Weird Compiling Error.

    What weird error? Please post it.

Similar Threads

  1. Error while compiling.
    By Troy05 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: July 21st, 2013, 02:16 PM
  2. ArrayList weird display error
    By PissMaster in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 9th, 2013, 05:42 AM
  3. Weird Error with java objectoutput/input streams
    By SparX in forum Java Networking
    Replies: 5
    Last Post: March 31st, 2013, 02:53 AM
  4. Compiling error
    By Bri4n in forum Java Theory & Questions
    Replies: 5
    Last Post: November 7th, 2011, 10:26 PM
  5. Compiling error
    By tangara in forum Java IDEs
    Replies: 3
    Last Post: September 4th, 2011, 04:00 AM