Results 1 to 5 of 5
  1. #1
    florida is offline Member
    Join Date
    Mar 2013
    Posts
    13
    Rep Power
    0

    Question to fix the error " .class expected"

    import java.io.DataInputStream;
    class prog
    {
    public static void main(String args[])
    {
    DataInputStream in = new DataInputStream(System.in);
    int a[],n,c=0;
    prog1 p = new prog1();
    try
    {
    System.out.println("enter the array size");
    n=Integer.parseInt(in.readLine());
    int a[]= new int[n];
    for(int i=0;i<=n;i++)
    {
    System.out.println("enter the element");
    a[i]=Integer.parseInt(in.readLine());
    }
    p.cal ( int[] a, int n );
    }
    catch (Exception e)
    { }
    }
    }
    class prog1
    {
    void cal (int x[], int y)
    {
    for(int i =0;i<=n;i++)

    {
    if(a[i]>=100 && a[i]<=200)
    {
    if((a[i]%7)==0)
    {
    c=c+a[i];
    }
    }
    }

    System.out.println("the value is"+ c);
    }
    }

    i am new to java. when i am executing the prog i got the following errors. help me to correct errors


    prog.java:19: '.class' expected
    p.cal ( int[] a, int n );
    ^
    prog.java:19: ';' expected
    p.cal ( int[] a, int n );
    ^
    prog.java:19: ';' expected
    p.cal ( int[] a, int n );
    ^
    pls help me.......... thank u..........

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: to fix the error " .class expected"

    Your calling methods wrong. When calling methods, you pass in variables or literals but you don't also pass in the parameter type. That is used only when you create method code, not when you call them. Re-read a decent tutorial on use of methods.

    For instance, you place type names when defining methods:

    Java Code:
    public static void foo(int parameter) {
      System.out.println("parameter is " + parameter);
    }
    But you don't use parameter types when you call the method:

    Java Code:
    public static void main {
    
       foo(int a); // this is wrong!
    
       int a = 3;
       foo(a);  // this is right!
    }
    Last edited by Fubarable; 03-03-2013 at 06:31 AM.

  3. #3
    florida is offline Member
    Join Date
    Mar 2013
    Posts
    13
    Rep Power
    0

    Default Re: to fix the error " .class expected"

    thanks it has worked..... when i am executing it i couldn't get results... it just read the value but don't get any answer.....
    Java Code:
    import java.io.DataInputStream;
    class digit
     {
       public static void main(String args[])
        {
          DataInputStream in = new DataInputStream(System.in);
          int n;
          prog1 p = new prog1();
          try
            {
     		System.out.println("enter the array size");
     		n=Integer.parseInt(in.readLine());
     		int a[]= new int[n];
     		for(int i=0;i<=n;i++)
     			{
     				System.out.println("enter the element");
     				a[i]=Integer.parseInt(in.readLine());
    			}
     		p.cal (a,n);
    	} 
          catch (Exception e){ }
        }
      }
    class prog1
    	{ 
              int c=0;
     		void cal(int x[], int y)
     			{
     				for(int i =0;i<=y;i++)
     
    					{
     						if(x[i]>=100 && x[i]<=200)
     							{
     								if((x[i]%7)==0)
     									{
     										c+=x[i];
     									}
     							}
     					}
     
    				System.out.println("the value is"+ c);
     			} 
    	}
    D:\bharathi\Java2\jdk1.6.0_33\bin>java digit
    enter the array size
    2
    enter the element
    109
    enter the element
    114
    enter the element
    112

    D:\bharathi\Java2\jdk1.6.0_33\bin>

    help me ........
    Last edited by JosAH; 03-03-2013 at 12:36 PM. Reason: added [code] ... [/code] tags

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default Re: to fix the error " .class expected"

    You're throwing away an Exception in line #21; print it out, i.e. e.printStackTrace(); and see why nothing is printed now ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    florida is offline Member
    Join Date
    Mar 2013
    Posts
    13
    Rep Power
    0

    Default Re: to fix the error " .class expected"

    thank u.............finally i got the output........ thank u so much guys...........

Similar Threads

  1. Replies: 4
    Last Post: 12-08-2012, 11:56 AM
  2. Syntax error on token "}", super expected
    By amentjacob1 in forum New To Java
    Replies: 9
    Last Post: 07-06-2012, 05:15 AM
  3. Replies: 4
    Last Post: 10-20-2011, 06:10 AM
  4. Syntax error on token "(", ; expected
    By baltimore in forum AWT / Swing
    Replies: 3
    Last Post: 10-28-2009, 01:19 AM
  5. Replies: 3
    Last Post: 12-05-2008, 09:34 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •