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.

Page 2 of 2 FirstFirst 12
Results 26 to 33 of 33

Thread: missing return statement need help!!

  1. #26
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: missing return statement need help!!

    Copy the text of the compiler's error into the clipboard and paste it here on the forum.
    The same as pasting java source code here: copy and paste.
    If you don't understand my answer, don't ignore it, ask a question.

  2. The Following User Says Thank You to Norm For This Useful Post:

    widowx (March 28th, 2013)

  3. #27
    Junior Member
    Join Date
    Mar 2013
    Posts
    15
    My Mood
    Confused
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default Re: missing return statement need help!!

    incompatible types -found int but expected boolen

  4. #28
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: missing return statement need help!!

    incompatible types -found int but expected boolen
    Where is the source line that is causing that error?

    The compiler found an int value/variable where it expected a boolean variable/value.
    Look at the code where the error is, Find the int value and replace it with a boolean value.
    If you don't understand my answer, don't ignore it, ask a question.

  5. The Following User Says Thank You to Norm For This Useful Post:

    widowx (March 28th, 2013)

  6. #29
    Junior Member
    Join Date
    Mar 2013
    Posts
    15
    My Mood
    Confused
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default Re: missing return statement need help!!

    owh...now i get it..the problem is i get confused with my first part of coding to be apply with second part which is game quiz start.
    the first part is store the question and answer.

    --- Update ---

    i get the point now...when compile there no syntax error
    Class compiled - no syntax error


    if i want to run the programm it give an error
    java.lang.ArrayIndexOutOfBoundsException: 50
    	at state.main(state.java:161)


    --- Update ---

    here my full coding edited
     
    /**
     * Write a description of class state here.
     * 
     * @author (your name) 
     * @version (a version number or a date)
     */
    import java.util.*;
    import java.io.*;
    import java.util.Scanner;
    public class state
    {
        public static void main(String [] args)throws FileNotFoundException
        {
        Scanner input=new Scanner(System.in);
     
     
     String s =" ";
     String[] data, category, option,option2,option3,option4;
     data = new String [50];
     category = new String[50];
     option = new String [50];
     option2 = new String [50];
     option3 = new String [50];
     option4 = new String [50];
     int numq;
     
     
     
     
     int [] choice, answer;
     choice = new int[50];
     answer = new int[50];
     
     
     
     
    System.out.printf(" Welcome to Quiz",s);
    System.out.printf("What to do?",s);
     
    System.out.println("1]Specify number of question you want to do");
     
    System.out.println("2]Enter the question CATEGORY");
     
    System.out.println("3]Enter the QUESTION for each category");
     
    System.out.println("4]Enter the OPTION for each question");
     
    System.out.println("5]Provide the ANSWER for each question");
     
    System.out.println("6]Then your QUIZ GAME is ready to be play by your friend");
     
    System.out.println("Press any key to start the game..");
    System.out.println();
     
     
     
           System.out.println("How many question you want to create:");
           choice[1]=input.nextInt();
           System.out.println();
           System.out.print("\f");
           input.nextLine();
           System.out.println("Please enter your question CATEGORY");
     
           for (int a=0; a<choice[1];a++)
           {
               System.out.print(choice[2]+1+"]  ");
               data[a]=input.nextLine();
               choice[2]=choice [2] + 1;
            }
            System.out.print("\f");
            System.out.println();
            System.out.println("Please enter your Question");
     
            for (int  b=0; b<choice[1];b++)
            {
     
                System.out.println();
                System.out.println(" Category: " + data[b]);
                System.out.println(choice[3] + 1 +" ] ");
                category[b]=input.nextLine();
                choice[3]=choice[3]+ 1;
            }
            System.out.print("\f");
            System.out.println();
            System.out.println("Please enter your question option ");
     
            for (int c=0; c<choice[1];c++)
            {
                System.out.println();
                System.out.println("question : " + category [c]);
                System.out.println();
     
                System.out.println("1]");
                option[c] = input.nextLine();
     
                System.out.println("2]");
                option2[c] = input.nextLine();
     
                System.out.println("3]");
                option3[c] = input.nextLine();
     
                System.out.println("4]");
                option4[c] = input.nextLine();
     
                System.out.println();
                System.out.println("please set the answerto this question");
                System.out.print("the answer is ");
                answer[c]= input.nextInt();
                input.nextLine();
                System.out.println();
            }
     
            System.out.println("your quiz game is now ready...press the enter to start ");
            input.nextLine();
            System.out.print("\f");
     
     
            System.out.println(" welcome to game quiz");
     
            System.out.println("Game rule; 1] select 1 topic");
     
            System.out.println("2] answer the mcq question");
     
            System.out.println("3] each correct answer will given 10 point");
     
            System.out.println("4] each incorrect answer will be deducted 10 point");
     
            System.out.println("5] the game will be over once your answer the question wrongly");
     
            System.out.println();
            System.out.printf(" press the enter key to start the game...");
            input.nextLine();
     
            System.out.print("\f");
     
     
     
    int Scorepoint= 0;
    int rounds =0;
    int c=50;
     
     
     while(rounds < choice[1])
     {
     System.out.println("please select a Category.");
      System.out.println("Your current point is :" +Scorepoint);
      {
      for (int i=0; i <choice[1]; i++);
    }
      choice[2]=choice[1];
     
      System.out.println(data);
      System.out.println("1]" + option); 
      System.out.println("2]" + option2); 
      System.out.println("3]" + option3); 
      System.out.println("4]" + option4); 
      System.out.println("what is your answer");
      int playerans = choice[2];
     
      if (playerans<=answer[c])
      {
          System.out.print("\f");
          System.out.println("your answer is correct");
          System.out.println("the answer is:" + answer[c]);
          System.out.println();
          Scorepoint += 10;
          rounds += 1;
        }
    else
        {
         System.out.print("\f");
         System.out.println("your answer is incorrect.");
         System.out.println("the answer is :" + answer[c]);
         System.out.println();
         Scorepoint -=10;
         rounds = choice[2];
        }
     
        playerans =0;
     
    }
    System.out.print("\f");
    System.out.println("game Over");
    System.out.println("your score:" + Scorepoint);
    }
    }


    --- Update ---

    please select a Category.
    Your current point is :0
    [Ljava.lang.String;@e3849c
    1][Ljava.lang.String;@11756a4
    2][Ljava.lang.String;@13936e1
    3][Ljava.lang.String;@141fab6
    4][Ljava.lang.String;@b301f2
    what is your answer
    what is this meant?

    --- Update ---

    I need help with above error and what should I do to fix...my coding

  7. #30
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: missing return statement need help!!

    java.lang.ArrayIndexOutOfBoundsException: 50
    at state.main(state.java:161)
    The index for an array at line 161 is past the end of the array. Look at the code at and before line 161 and see why the index got too big.
    Remember array indexes range in value from 0 to the array length-1

    [Ljava.lang.String;@e3849c
    That String is what is returned by a String array's toString() method.
    If you want to print the contents of an Array use the Arrays class's toString() method:
    System.out.println("an ID "+ java.util.Arrays.toString(theArrayName));
    If you don't understand my answer, don't ignore it, ask a question.

  8. #31
    Junior Member
    Join Date
    Mar 2013
    Posts
    15
    My Mood
    Confused
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default Re: missing return statement need help!!

    **
     * Write a description of class state here.
     * 
     * @author (your name) 
     * @version (a version number or a date)
     */
    import java.util.*;
    import java.io.*;
    import java.util.Scanner;
    public class state
    {
        public static void main(String [] args)throws FileNotFoundException
        {
                  Scanner input=new Scanner(System.in);
     
     
                     String s =" ";
               String[] data, category, option,option2,option3,option4,playera;
                data = new String [50];
                category = new String[50];
                option = new String [50];
                option2 = new String [50];
                option3 = new String [50];
                option4 = new String [50];
     
                int numq;
     
     
     
     
                int[] choice, answer;
                choice = new int[50];
                answer = new int[50];
     
     
     
     
     
                System.out.printf(" Welcome to Quiz",s);
                System.out.printf("What to do?",s);
     
                System.out.println("1]Specify number of question you want to do");
     
                System.out.println("2]Enter the question CATEGORY");
     
                System.out.println("3]Enter the QUESTION for each category");
                System.out.println("4]Enter the OPTION for each question");
                System.out.println("5]Provide the ANSWER for each question");
                System.out.println("6]Then your QUIZ GAME is ready to be play by your friend");
                System.out.println("Press any key to start the game..");
                System.out.println();
     
     
     
           System.out.println("How many question you want to create:");
           choice[1]=input.nextInt();
     
           System.out.println();
           System.out.print("\f");
           input.nextLine();
           System.out.println("Please enter your question CATEGORY");
     
           for (int a=0; a<choice[1];a++)
           {
               System.out.print(choice[2]+1+"]  ");
               data[a]=input.nextLine();
               choice[2]=choice [2] + 1;
            }
            System.out.print("\f");
            System.out.println();
            System.out.println("Please enter your Question");
     
            for (int  b=0; b<choice[1];b++)
            {
     
                System.out.println();
                System.out.println(" Category: " + data[b]);
                System.out.println(choice[3] + 1 +" ] ");
                category[b]=input.nextLine();
                choice[3]=choice[3]+ 1;
            }
            System.out.print("\f");
            System.out.println();
            System.out.println("Please enter your question option ");
     
            for (int c=0; c<choice[1];c++)
            {
                System.out.println();
                System.out.println("question : " + category [c]);
                System.out.println();
     
                System.out.printf("1]");
                option[c] = input.nextLine();
     
                System.out.printf("2]");
                option2[c] = input.nextLine();
     
                System.out.printf("3]");
                option3[c] = input.nextLine();
     
                System.out.printf("4]");
                option4[c] = input.nextLine();
     
                System.out.println();
                System.out.println("please set the answerto this question");
                System.out.print("the answer is ");
                answer[c]= input.nextInt();
                input.nextLine();
                System.out.println();
            }
     
            System.out.println("your quiz game is now ready...press the enter to start ");
            input.nextLine();
            System.out.print("\f");
     
     
            System.out.println(" welcome to game quiz");
     
            System.out.println("Game rule; 1] select 1 topic");
     
            System.out.println("2] answer the mcq question");
     
            System.out.println("3] each correct answer will given 10 point");
     
            System.out.println("4] each incorrect answer will be deducted 10 point");
     
            System.out.println("5] the game will be over once your answer the question wrongly");
     
            System.out.println();
            System.out.printf(" press the enter key to start the game...");
            input.nextLine();
     
            System.out.print("\f");
     
     
     
          int Scorepoint= 0;
              int rounds =0;
           int c=50;
              int playerans=0;
     
     
                while(rounds < choice[1])
               {
              int Noq;
     
               System.out.println("please select a Category.");
                for (int a=0; a<choice[1];a++)
               {
     
               System.out.println(" Category: " + data[a]);
            }
     
     
     
     
               System.out.println("Your current point is :" +Scorepoint);
               system.out.println;
               Noq = input.nextInt();
     
              for (int i=0; i <choice[1]; i++){
     
                   choice[i]=choice[3];
     
                 System.out.println(choice[1]);
                 System.out.println("1]" + option); 
                 System.out.println("2]" + option2); 
                 System.out.println("3]" + option3); 
                 System.out.println("4]" + option4); 
                 System.out.println("what is your answer");
                  answer[c] = input.nextInt();
     
     
                    if (answer[c] == choice[i])
                 {
                   System.out.print("\f");
                   System.out.println("your answer is correct");
                   System.out.println("the answer is:" + answer[c]);
                   System.out.println();
                   Scorepoint += 10;
                   rounds += 1;
                  }
                 else
                    {
                  System.out.print("\f");
                  System.out.println("your answer is incorrect.");
                  System.out.println("the answer is :" + answer[c]);
                  System.out.println();
                  Scorepoint -=10;
                  rounds = choice[2];
                 }
     
               playerans =0;
     
              }
               System.out.print("\f");
               System.out.println("game Over");
               System.out.println("your score:" + Scorepoint);
          }
        }
     
     }

    i got a 'statement error'..
    can u help abit how to fix or hint..

  9. #32
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: missing return statement need help!!

    i got a 'statement error'..
    Please copy the full text of the error message and paste it here.
    If you don't understand my answer, don't ignore it, ask a question.

  10. #33
    Junior Member
    Join Date
    Mar 2013
    Posts
    15
    My Mood
    Confused
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default Re: missing return statement need help!!

    Thanks for helping me with coding. . Now my problem solved

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Missing return statement
    By beerye28 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: January 23rd, 2013, 06:48 PM
  2. Missing return statement
    By mrroberts2u in forum What's Wrong With My Code?
    Replies: 4
    Last Post: May 10th, 2011, 06:11 AM
  3. Missing return statement
    By Stn in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 1st, 2011, 08:03 PM
  4. Prime number generator program missing return statement
    By 03EVOAWD in forum What's Wrong With My Code?
    Replies: 13
    Last Post: September 10th, 2009, 09:17 AM
  5. Error of "Class has no return statement"
    By mdstrauss in forum What's Wrong With My Code?
    Replies: 7
    Last Post: August 2nd, 2009, 12:00 PM