![]() |
| ||
| missing return statement Hi guys, Im trying to compile this class below, but its just not working, it keeps sating 'missing return statement' int the method declaration line. Can u see to check if there is anything missing in my code or if iv done something wrong?? Thanks! public class swapping { public int trade(int []a, int b){ //says theres a missing return statement int temp=0; for (int n = 1; n < b; n++) { for (int m = 0; m < b - 1; m++) { if (a[m] > a[m] + 1) { temp = a[m]; a[m] = a[m+1]; a[m+1] = temp; return a[m]; } } } } } |
| ||
| Re: missing return statement hello everyone, Your class main is missing and you added an extra bracket at the end Yours Sincerely Richard West |
| ||
| Re: missing return statement Well I'm sure that i_me_roo probably has a main and extra bracket at the end. The compiler complaint was about return statements. i_me_roo if you look at the code, you'll see that it is possible to go straight through the function without hitting the return statement. This is what the compiler is complaining about. The function returns an int, so all paths of execution must have a return value; My suggestion is to have a 'return ERROR', or 'return 0', or 'return -1' after the for loops if you never intend to reach that line of execution. This is the best advice I can think of since I have no idea about the context of the function you wrote. Ed |
| ||
| Re: missing return statement public class swapping {Now it'll run well. |
| ||
| Re: missing return statement Thank you very much for ur help all of u, it is working now!! Thanks! |
| ||
| missing return statement hi everyone i'm new to programming and i have to say its fun and frustrating at the same time could anyone help me fix this?? // Exercise5_2.java: Create a method for summarizing digits in an int public class Exercise5_2 { public static void main(String[] args) { // Create a Scanner java.util.Scanner input = new java.util.Scanner(System.in); System.out.print("Enter a number: "); long value = input.nextInt(); String t = getSum(value); System.out.print(t); } public static String getSum(long value) { //FILL IN THE METHOD long remainingAmount = value; long n1 = remainingAmount / value; remainingAmount = remainingAmount % value; long n2 = remainingAmount / value; remainingAmount = remainingAmount % value; long n3= remainingAmount / value; remainingAmount = remainingAmount % value; long n4 = remainingAmount / value; remainingAmount = remainingAmount % value; long n5 = remainingAmount / value; remainingAmount = remainingAmount % value; long n6 = remainingAmount / value; remainingAmount = remainingAmount % value; long n7= remainingAmount / value; remainingAmount = remainingAmount % value; long n8 = remainingAmount / value; remainingAmount = remainingAmount % value; long n9 = remainingAmount; // Do the math to add digits together long total = (n1 + n2 + n3 + n4 + n5 + n6 + n7 + n8 + n9); System.out.println("The sum of digits for " + value + " is " + total); }// HERE IT SAYS THAT I AM MISSING A RETURN STATEMENT } |
| ||
| Quote:
If it says it is missing a return statement, then add one since your method is declared to return a String. If you have any more questions start a new thread. |
| ||
| Quote:
|
| All times are GMT -4. The time now is 1:29 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC