hello everyone,
Your class main is missing and you added an extra bracket at the end
Yours Sincerely
Richard West
freesoft_2000
Practically a Master Poster
623 posts since Jun 2004
Reputation Points: 25
Solved Threads: 10
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];
}
}
}
return 0;
}
}
Now it'll run well.
nanosani
Unauthenticated Liar
1,830 posts since Jul 2004
Reputation Points: 45
Solved Threads: 56
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??
This is a 5 year old thread. That were you thinking posting here? Do you random peek threads and start writing irrelevant things in them?
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.
javaAddict
Nearly a Senior Poster
3,329 posts since Dec 2007
Reputation Points: 1,014
Solved Threads: 448
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);
string mySum;
//Copy total to mySum
retun mySum;
}// HERE IT SAYS THAT I AM MISSING A RETURN STATEMENT
}
You need to make a string out of the integer total and return it
ithelp
Nearly a Posting Maven
2,230 posts since May 2006
Reputation Points: 769
Solved Threads: 128
i have the same problem! missing return statement
class MOrders
{
int nooforders;// Data members of the class
public int getorder()
{
nooforders = 500;
}
public int displayorders()
{
System.out.println("The number of orders to be delivered:"+ nooforders);
}
public static void main(String args[])
{
MOrders obj = new MOrders ();
obj.getorder();
obj.displayorders();
}
}
Did you bother to read the rest of the thread with the answers. You resurrected an old thread just to post a question that has already been answered? Are you too lazy to read the suggestions and advices given and you want some one just to tell you again the answer, instead of you spending 5 minutes to read the rest of the thread?
If it says "missing return statement" then you haven't put a "return" statement. Why you should put one? Read the rest of the thread.
Also, the errors that you get tell you exactly where the error is at your code. Read those errors.
javaAddict
Nearly a Senior Poster
3,329 posts since Dec 2007
Reputation Points: 1,014
Solved Threads: 448
that's because your class is filled with errors. you are telling the compiler that you are returning an int, both in getOrder() and displayOrders(), but you have no return statement, nor do you have a variable in which you store the value in your main method, or a print in which the value is shown.
next to that: if you would've looked at the post you're answering to, you would've seen it's a post that dates back to 2004. There is no use what so ever to revive this thread. if you have a question, just create a new thread.
and since I've answered your question in my first paragraph, and give you enough info to correct your code, there is no need to create another thread with this question.
stultuske
Posting Sensei
3,122 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
I will be happy to explain the answer - your confusion here is actually reasonable - if you'll be kind enough to
a)start a new thread for this question, since we don't like new questions in old threads, it's contrary to the house style
and
b) put code tags around your code, so it comes out formatted legibly.
jon.kiparsky
Posting Virtuoso
1,849 posts since Jun 2010
Reputation Points: 383
Solved Threads: 187