Results 1 to 3 of 3
  1. #1
    artur is offline Member
    Join Date
    Nov 2011
    Posts
    15
    Rep Power
    0

    Default Arrays Counting Number of Occurrences

    Hi I have a quick question. Why do compiler keep saying that "continue" and "break" are outside of a loop.


    Java Code:
         import java.util.Scanner;
         
         public class problem1 {
         
           public static void main (String[] args) { 
           
    	  
           int input = 0;
           int[] integers = new int[51];
           Scanner scan = new Scanner(System.in);
     
    	   
          while(input != 51); {
    	         
    	   System.out.print("Enter an arbitrary number of integers in the range 0-50 (enter 51 to exit) : ");
    	   input = scan.nextInt();
               if(input == 51) break;
               if(input < 0 || input > 50){
    	           System.out.println("number out of range");
    	           }
    	    integers[input]++; 
               continue;
                  
                }   
                   
                for(int index = 0; index < 51; index++);
                   if(integers[index] > 0)
                       System.out.println(index + ": " + integers[index]);
              
              
            }   
             
        
       }

    The assignment is to design and implement an application that reads an arbitrary number of
    integers that are in the range 0 to 50 inclusive and counts how many
    occurences of each is entered. After all input has been processed,
    print all of the values (with the number of occurences) that were
    entered one or more times.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,891
    Rep Power
    25

    Default Re: Arrays Counting Number of Occurrences

    Why do compiler keep saying that "continue" and "break" are outside of a loop.
    Please post the full text of the error messages.

    Have you checked your looping code to make sure the statements are inside of a loop?
    while(input != 51); {

  3. #3
    artur is offline Member
    Join Date
    Nov 2011
    Posts
    15
    Rep Power
    0

    Default Re: Arrays Counting Number of Occurrences

    i can't believe i haven't notice the semicolon, it works now, thanks a lot

Similar Threads

  1. print out occurrences of number in a string
    By katiebear128 in forum New To Java
    Replies: 12
    Last Post: 10-26-2011, 12:36 AM
  2. Counting number of palindromes in a file
    By vuzuggu in forum New To Java
    Replies: 3
    Last Post: 10-20-2011, 06:52 PM
  3. Number of occurrences in a int[ ]
    By random0munky in forum New To Java
    Replies: 10
    Last Post: 10-10-2009, 11:22 PM
  4. counting number of lines of system.out
    By IYIaster in forum New To Java
    Replies: 1
    Last Post: 07-21-2009, 01:37 AM
  5. Replies: 20
    Last Post: 05-14-2008, 10:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •