Ask Experts Questions for FREE Help !
Ask
    arko93's Avatar
    arko93 Posts: 1, Reputation: 1
    New Member
     
    #1

    Jun 2, 2015, 10:15 AM
    Java
    class Cons
    {
    int a,c,k=0;
    int number()
    {
    for(a=1;a<=10;a++)
    {


    for(c=1;c<=a;c++)
    {

    if(a%c==0)
    k++;
    }
    }

    if(k==2)
    {
    System.out.println("prime numbers are"+a);
    }

    }
    int number(int x,int y)
    {
    a=x;
    c=y;
    for(a=1;a<=10;a++)
    {


    for(c=1;c<=a;c++)
    {

    if(a%c==0)
    k++;
    } } }



    }
    public class Prime
    {
    public static void main(String[]args)
    {
    Cons t=new Cons();
    System.out.println("result = "+t.number());
    Cons t1=new Cons(20,30);
    System.out.println("result = "+t1.number());

    }
    }

    Why I am getting an error in this program
    error- Prime.java:22: error: missing return statement
    }
    ^
    Prime.java:35: error: missing return statement
    } } }
    ^
    Prime.java:46: error: constructor Cons in class Cons cannot be applied to given types;
    Cons t1=new Cons(20,30);
    ^
    required: no arguments
    found: int,int
    reason: actual and formal argument lists differ in length
    CravenMorhead's Avatar
    CravenMorhead Posts: 4,532, Reputation: 1065
    Adult Sexuality Expert
     
    #2

    Jun 2, 2015, 01:26 PM
    The general form of a function declaration is:;
    |---------- Return value type.
    \/
    int funcationName(int Parameters)

    A simple function might be:

    int add2num(int num1, int num2)
    {
    int sum = num1 + num2;
    return sum;
    }

    Quote Originally Posted by arko93 View Post
    class Cons
    {
    int a,c,k=0; // CMH: You Can't initialize members in a class declaration,
    // Do in the constructor. Maybe these should be local to your methods and not class
    // members
    int number()
    { //fun
    for(a=1;a<=10;a++)
    {//for a


    for(c=1;c<=a;c++)
    {//for c

    if(a%c==0)
    k++;
    } //for c
    }//for a

    if(k==2)
    {
    System.out.println("prime numbers are"+a);
    }

    } // fun

    // You just ended the declaration of the above member. You have the value K, what are you doing with it here? Should you return it?

    int number(int x,int y)
    {
    a=x;
    c=y;
    for(a=1;a<=10;a++)
    {


    for(c=1;c<=a;c++)
    {

    if(a%c==0)
    k++;
    } } }

    // You just ended the declaration of the above member. You have the value K, what are you doing with it here? Should you return it?

    }
    public class Prime
    {
    public static void main(String[]args)
    {
    Cons t=new Cons(); // You only need to allocate this one.
    System.out.println("result = "+t.number());
    Cons t1=new Cons(20,30); // The numbers here
    System.out.println("result = "+t1.number());// should be the parameter list for this.

    }
    }

    Why I am getting an error in this program
    error- Prime.java:22: error: missing return statement
    }
    ^
    Prime.java:35: error: missing return statement
    } } }
    ^
    Prime.java:46: error: constructor Cons in class Cons cannot be applied to given types;
    Cons t1=new Cons(20,30);
    ^
    required: no arguments
    found: int,int
    reason: actual and formal argument lists differ in length
    I added comments to your code. I am not going to rewrite it for you, goodness knows it's tempting, but it is easy enough to fix.

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

What all topics comes under advance java?what is framework how it is related to java? [ 0 Answers ]

I want to know about the topics related to advance java?and how the framework likke struts and hibernate realted to each other?what are there uses?

I am new to java GUI and multiple classes, I have knowledge of core java. I have [ 0 Answers ]

Sir, I am new to java GUI and multiple classes, I have knowledge of core java. I have to call a rest client from my net beans project give values to it and receive it's output in the same project. Please suggest me what I need to study and what to do.

Java help please [ 0 Answers ]

15 points: Correct the errors in the following classes. Class1 must remain/become abstract and Class2 must remain/become concrete. All errors must be corrected. Public abstract class Class1 { Private int x; Protected int y; Public Class1(int x) { This.x = x; Y = 2; }

Java netbeans program- Connection between java and mysql,How to conn [ 0 Answers ]

which I wrote from a book but when I run it, it shows exception please give me the code to connect jlistbox to database when I click on btn1. btn coding should search "name" in database and shows all the names in listbox my coding: here-- r1,r2,r3 are radio btns and l1,l2,l3 are labels,...

Java [ 2 Answers ]

Write a program that converts 10, 50, and 100 kilograms to pounds


View more questions Search