Results 1 to 4 of 4
  1. #1
    lala is offline Member
    Join Date
    Oct 2010
    Posts
    80
    Rep Power
    0

    Default Unreachable statement

    all i want to do is print the values returned by the method test. No matter where I put the system.out.print statement, the compiler "barks".
    Everything I've read tells me that these errors will occur, BUT they do not tell me how to resolve the errors. (arrrrrrrrrggggggggghhhhhhhhh) I should taken quantum physics. Insanity would've overcome me sooner :mad:

    Java Code:
    import java.util.*;
    import javax.swing.JOptionPane;  
    	 
    	public class Ex6e {
    	
    	public static void main(String[] args)  {
    	}
    	public static int test (int x, char ch, double d, int y) {
      		
      		x = 5;
    		ch = 'z';
    		d = 7.3;
    		y=5;
    		
    		return (x);
    		System.out.print(x);					
    				
    		}
     }
    Errors:
    Ex6e.java:16: unreachable statement
    System.out.print(x);
    ^
    Ex6e.java:18: missing return statement
    }

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    6

    Default

    in the line before , with return (x) you leave the method, so the System.out is unreachable!
    change these two lines !

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Once a method calls returns, the method ends. You've got a statement after the return that will never be called.

  4. #4
    lala is offline Member
    Join Date
    Oct 2010
    Posts
    80
    Rep Power
    0

    Default (SOLVED) Unreachable statement

    Many,many thanks eRaaaa, & Fubarable.
    Deep gratitude.

Similar Threads

  1. Unreachable statement Pig Dice Game
    By noturn10 in forum New To Java
    Replies: 2
    Last Post: 11-22-2009, 01:36 AM
  2. The if Statement, need some help!
    By Keno777 in forum New To Java
    Replies: 6
    Last Post: 10-24-2009, 01:53 AM
  3. Replies: 6
    Last Post: 03-11-2009, 05:38 PM
  4. unreachable statement - Java calculator program
    By V2001Gordon in forum New To Java
    Replies: 3
    Last Post: 12-13-2008, 01:57 AM
  5. Statement or Prepared Statement ?
    By paty in forum JDBC
    Replies: 3
    Last Post: 08-01-2007, 05:45 PM

Posting Permissions

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