-4
import java.util.Scanner ;
public class ProcessNumbers
{
public static void main( String[] args )
{
    Scanner in = new Scanner(System.in) ;
    System.out.print("Please enter an integer between 6 and 12, inclusive: ") ;
    int num = in.nextInt() ;
    boolean result = shouldProcess(num);
    String result1 = processInput(result) ;
}
    public static boolean shouldProcess(int n)
    {
        if (n>=6 && n<12)
        {
            return true;
        }
        else
        {
            return false;
        {
     }
     public static String processInput(String result2)
     {
         if (result2 = result)
         {
             System.out.println("Yes") ; 
         }
         else 
         {
             System.out.println("No") ;
     }
  }
}

I am trying to work through an example that wants me to code a program where a boolean method shouldProcess returns true if the number given by the user is between 6 and 12, which I have done. Next, I want to use the method called processInput which uses the previous shouldProcess to see if the value is true or false. If it is true I will then go on to do some other calculations; however if it is false then I want to say that the number is not valid.

When I input a value, I get this error:

 [File: /ProcessNumbers.java Line: 27, Column: 10] illegal start of expression
 [File: /ProcessNumbers.java Line: 27, Column: 17] illegal start of expression
 [File: /ProcessNumbers.java Line: 27, Column: 30] ';' expected
 [File: /ProcessNumbers.java Line: 27, Column: 50] ')' expected
 [File: /ProcessNumbers.java Line: 27, Column: 58] illegal start of expression
 [File: /ProcessNumbers.java Line: 27, Column: 59] ';' expected
[File: /ProcessNumbers.java Line: 38, Column: 2] reached end of file while parsing
jh123
  • 173
  • 1
  • 8

2 Answers2

0

You're putting methods inside of methods:

public static void main(String[] args)
{
    //...
    public static boolean shouldProcess(int n)
    {
        //...
    }
}

That's invalid syntax/structure. Methods belong inside the class, not each other:

public static void main(String[] args)
{
    //...
}

public static boolean shouldProcess(int n)
{
    //...
}
David
  • 208,112
  • 36
  • 198
  • 279
  • oh so my brackets is what is messing up then i have to close each method so they dont overlap – jh123 Jun 26 '16 at 23:27
  • @javahelper123: You already do call the method: `boolean result = shouldProcess(num);` – David Jun 26 '16 at 23:27
  • I have made cvhanges to my program – jh123 Jun 26 '16 at 23:31
  • @javahelper123: You're also trying to assign a value in a conditional statement: `if (result2 = result)` You probably meant to compare the value: `if (result2 == result)` Although that's not how you compare strings in Java. (http://stackoverflow.com/q/513832/328193) Also, `result` doesn't exist in that method. – David Jun 26 '16 at 23:35
  • so how do i fix that result? i did mean to cmpare the strings which i did incorrectly – jh123 Jun 26 '16 at 23:40
  • @javahelper123: For comparing the values, check the link to the other question. For using the `result` variable, pass both variables to that method. – David Jun 26 '16 at 23:41
0

A method inside a method is unacceptable in Java. However, when you are calling a method, you may call another method inside the parenthesis if the second method returns a data type that matches the data type of the first method's explicit parameter.

Here are the errors I found:

  1. When you set result2 equal to a method, you have passed A BOOLEAN as the explicit parameter, whereas your processInput() method defines a STRING data type as the parameter. This will give a data type mismatch error.

  2. You have an open bracket where you need a close bracket.

NOTE: If you receive an error message, locate the line of the error, and if you don't know what the error means, look it up on this website or any other known one.