Saturday, November 19, 2011

Java Programme1

public class ExampleClass1 {
public int  exMethod()
{
   int r = 1;
   r+=x;

if( (x>4)  && (x<10) )
{
         r+=2*x;
}
else(x<=4)
{
  r+=3*x;
}
else()
{
r+=4*x;
}
r+=5*x;
return x;
}

public static void main(String[] args)
{
Function1 f1=new Function1();
System.out.println("OF(11)  is "+ f1.exMethod(11));
}
}

The above programme on compilation gives out compilation error. This is because 'if' should not be followed by two 'else' statements immediately.

No comments:

Post a Comment