-6

The program is as follows...

 public class SDD
 {
    public static void main(String args[])
    {
        int x=0, y=10;

        do{

            ++x;

            y-=x++;

        }while(x<=7);
        return(y);
    }
}

The error is as follows......

Cannot return a value from method whose type is void.

Noushad
  • 369
  • 3
  • 10

3 Answers3

0
 public class SDD
    {
        public static void main(String args[])
        {
          int x=0, y=10;   
          do{    
             ++x;    
             y-=x++;

           }while(x<=7);
          System.out.println(y);
        }
   }
Musaddique
  • 1,295
  • 1
  • 11
  • 28
0

Your main method is declared as void, so it cannot return a value. The last line (return y) is trying to return the value of y. This is not allowed.

If you want to display the content of y, you could replace that line with:

System.out.println("y = " + y);

Max D
  • 179
  • 10
0

Remove this line .

 return(y);

Add this line :

System.out.println("y = " + y);

or you can rewrite the program as follows :

public class SDD
 {
    public static int main(String args[])
    {
        int x=0, y=10;

        do{

            ++x;

            y-=x++;

        }while(x<=7);
        return(y);
    }
}
A Stranger
  • 1,816
  • 2
  • 24
  • 58