Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: Please Help me Find the Error

  1. #1
    Junior Member
    Join Date
    Dec 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Please Help me Find the Error

    In the Following Simple programs im getting a common error. missing return statement. Please help me find the repeated error committed by me.

    program 1:

    import java.io.*;

    class jugal
    {
    int i,j;
    /* jugal(int i,int j)
    {
    this.i=i;
    this.j=j;
    }*/

    public int disp(int i,int j)
    {
    this.i=i;
    this.j=j;
    return i+j;
    }
    }

    class sample
    {
    public static Void main(String a1[])
    {
    jugal j1=new jugal();
    System.out.println(j1.disp(5,5));
    int a=Integer.parseInt(a1[0]);
    int b=Integer.parseInt(a1[1]);
    jugal j2=new jugal();
    int c=j2.disp(a,b);
    System.out.println("show" +c);
    }
    }


    program 2:

    interface example
    {
    final int a=5;
    Void show();
    }

    class jugal implements example
    {
    public Void show()
    {
    System.out.println(a*a);
    }

    }

    class sample1
    {
    public static Void main(String a1[])
    {
    jugal j1=new jugal();
    j1.show();
    }
    }


    program 3:

    class jugal implements Runnable
    {
    Thread t;
    jugal()
    {
    t=new Thread(this,"demo");
    System.out.println(t);
    t.start();
    }
    public Void run()
    {
    try
    {
    for(int i=1;i<10;i--);
    {
    System.out.println(i);
    Thread.sleep(500);
    }
    }
    catch(InterruptedException e)
    {
    System.out.println(e);
    }
    }
    }

    class sample2
    {
    public static Void main(String a[])
    {
    new jugal();
    try
    {
    for(int i=1;i<10;i--);
    {
    System.out.println(i);
    Thread.sleep(1000);
    }
    }
    catch(InterruptedException e)
    {
    System.out.println(e);
    }
    }
    }


    program 4:


    import java.util.*;

    public class sample5
    {
    public static Void main(String a[])
    {
    int c[]={5,7,1,3,2};
    Set<Integer> s=new HashSet<Integer>();

    for(int i=0;i<5;i++)
    {
    s.add(c[i]);
    }
    System.out.println(s);

    TreeSet ss=new TreeSet<Integer>(s);
    System.out.println(ss.first());
    System.out.println(ss.last());

    }
    }


    program 5:

    import java.util.*;

    public class sample6
    {
    public static Void main(String a[])
    {
    int c[]={4,6,2,1,9};
    List<Integer> l=new ArrayList<Integer>();

    for(int i=0;i<5;i++)
    {
    l.add(c[i]);
    }
    System.out.println(c);

    LinkedList<Integer> l1=new LinkedList<Integer>(l);

    for(int i=0;i<5;i++)
    {
    l1.addFirst(c[i]);
    }
    System.out.println(l1.removeLast());
    }
    }


    program 6:


    import java.util.*;

    public class sample7
    {
    public static Void main(String a[])
    {
    String s[]={"sun","mon","tues","wed","thrus"};

    Map m=new HashMap();
    for(int i=0;i<5;i++)
    {
    m.put(i,s[i]);
    }
    TreeMap t=new TreeMap(m);
    System.out.println(t.keySet());
    System.out.println(t.firstkey()+" value: "+t.get(t.firstKey()));
    System.out.println(t.lastKey()+" "+t.get(t.lastKey()));
    System.out.println(t.remove(t.lastkey()));
    System.out.println(t.values());
    System.out.println(t.keySet());
    }
    }


    program 7:

    import java.util.Vector;
    import java.util.Enumeration;

    class sample8
    {
    public static Void main(String a[])
    {
    Vector<Object> v=new Vector<Object>();
    int p=20;
    Integer i=new Integer(20);
    String s=new String("Jugal");
    v.add(i);
    v.add(p);
    v.add(s);
    System.out.println(v);
    v.add(2,new Integer(10));
    System.out.println(v);
    System.out.println(v.elementAt(2));
    System.out.println(v.firstElement());
    System.out.println(v.lastElement());
    v.removeElementAt(2);
    System.out.println(v);
    System.out.println(v.firstElement());
    System.out.println(v.lastElement());
    Enumeration e=v.elements();
    while(e.hasMoreElements())
    {
    System.out.println(e.nextElement());
    }
    }
    }


  2. #2
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    1,069
    Thanks
    7
    Thanked 215 Times in 191 Posts

    Default Re: Please Help me Find the Error

    Case matters in Java, so void is what we use if we don't return anything. And Void is something else which you almost certainly don't want to use (but if it is used then an instance of Void must be returned.)

  3. #3
    Junior Member
    Join Date
    Dec 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Please Help me Find the Error

    can you help me understand the error, with an simple example.

  4. #4
    Member
    Join Date
    Dec 2011
    Location
    United States
    Posts
    94
    My Mood
    Amused
    Thanks
    5
    Thanked 8 Times in 8 Posts

    Default Re: Please Help me Find the Error

    Try to enclose your codes with [highlight = java] code here [/java] for easy reading by potential helpers.

  5. #5
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Please Help me Find the Error

    can you help me understand the error, with an simple example.
    Example:
    public int returnSomething(int a,int b){
             return (a+b);
    }

  6. #6
    Junior Member
    Join Date
    Dec 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Please Help me Find the Error

    thanks for the rep. Im a beginner in java. Would plz make it more precise, like where im i suppose to use /java exactly.

  7. #7
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Please Help me Find the Error

    Read the second reply to this thread and you will find the answer.

  8. #8
    Member
    Join Date
    Dec 2011
    Location
    United States
    Posts
    94
    My Mood
    Amused
    Thanks
    5
    Thanked 8 Times in 8 Posts

    Default Re: Please Help me Find the Error

    Look at the (V) in the main method. Try changing it to lowercase (v). Again, read the second response to your question.

Similar Threads

  1. [SOLVED] cannot find symbol error
    By Topflyt in forum What's Wrong With My Code?
    Replies: 9
    Last Post: November 5th, 2011, 09:57 AM
  2. Cannot find symbol ERROR
    By yacek in forum What's Wrong With My Code?
    Replies: 8
    Last Post: October 22nd, 2011, 12:39 AM
  3. can any one plz find the error.
    By shalini_sns in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 23rd, 2011, 06:26 PM
  4. Cannot find symbol error
    By AnuR in forum What's Wrong With My Code?
    Replies: 9
    Last Post: February 23rd, 2011, 02:50 PM
  5. Need help, cannot find error
    By Imeri0n in forum What's Wrong With My Code?
    Replies: 13
    Last Post: December 5th, 2010, 05:26 PM