Page 1 of 2 12 LastLast
Results 1 to 20 of 32
  1. #1
    amrmb09 is offline Member
    Join Date
    Nov 2010
    Posts
    75
    Rep Power
    0

    Default I dont know what's wrong with line 36. please help

    import java.util.*;
    class Op
    {
    private int arraysize;
    private double operand1, operand2;
    private int numofoperands;

    Scanner read=new Scanner(System.in);
    String scandata, scaninput;
    int scannumofoperands,scanoperandsindex;
    private String [] workarray;
    public String [] dataarray;

    public void setsize(int size)
    {
    arraysize=size;
    }

    public void initialize()
    {
    dataarray = new String [arraysize];
    System.out.println("your array initialized with "+dataarray.length+" elements"); //+arraysize+ wrong, instead, dataarray.length

    for (int i=1;i<=dataarray.length;i++)
    {
    System.out.println("x["+i+"] = ");
    scandata=read.nextLine();
    dataarray[i]=scandata;
    }
    }


    public void getnumofoperands()
    {
    for (int i=1; i<=dataarray.length; i++);
    System.out.println(dataarray[i]);

    do{
    System.out.println("enter number of operands - 2 operands or more - :");
    scannumofoperands = read.nextInt();
    if (scannumofoperands >= 2)
    {
    int workarraysize = scannumofoperands;
    workarray = new String [workarraysize];
    for (int i=1; i<=workarray.length; i++)
    {
    System.out.println("enter the index of the numbers you want to use:");
    scanoperandsindex = read.nextInt();
    workarray[i] = dataarray[scanoperandsindex];
    } // end for
    }// end if
    }while (scannumofoperands<2); // end of do-while
    }


    public void main (String [] args)
    {
    Scanner read = new Scanner (System.in);
    String scanchoice;
    int size, choice,value;

    do
    {
    System.out.println("choose an operation: 1:+ 2:- 3:* 4:/");
    scanchoice = read.nextLine();
    choice = Integer.parseInt(scanchoice);

    switch (choice)
    {
    case '1' : System.out.println("enter number of elements:");
    value=read.nextInt();
    setsize(value);
    initialize();
    getnumofoperands();
    /* pluseop(operand1,operand2);
    case '2' : initialize();
    subop(operand1,operand2);
    case '3' : initialize();
    mulop(operand1,operand2);
    case '4' : initialize();
    divop(operand1,operand2);*/
    }; // end switch
    } while(choice!=1 || choice!=2 || choice!=3 || choice!=4); // end do-while




    }

    }

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default

    the semicolon on the end of the line before :D

  3. #3
    amrmb09 is offline Member
    Join Date
    Nov 2010
    Posts
    75
    Rep Power
    0

    Default

    Quote Originally Posted by eRaaaa View Post
    the semicolon on the end of the line before :D
    thank you so much
    but, when compiling there is still an exception in the main thread.why??

  4. #4
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default

    which exception?
    --> Exception in thread "main" java.lang.NoSuchMethodError: main <- that one? :)

    the main method must be static! public static void main(String[] args)
    But you will get other errors, because the methods setsize,initialize and getnumofoperands are no static methods, so you have to call them on a instance of the OP class (read the differences between static - non-static)

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

    Default

    You may want to show us the actual exception text and indicate which line is causing it (not by line number but by posting the actual line).

    Luck!

  6. #6
    amrmb09 is offline Member
    Join Date
    Nov 2010
    Posts
    75
    Rep Power
    0

    Default Thank u all

    many thanks for your help

  7. #7
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    837
    Rep Power
    6

    Default

    not only 36th line.some more errors are there.

    Learn the basics and start doing the code.

    1.You should have proper main.

    2.Main method is static ,so have to call the method from main by making all the method as static one or create an instance and call the methods.
    Ramya:cool:

  8. #8
    amrmb09 is offline Member
    Join Date
    Nov 2010
    Posts
    75
    Rep Power
    0

    Default please help, what is the problem with the main()

    Java Code:
    import java.util.*;
    import java.io.*;
    public class Op
    {
    	public  int arraysize;
    	private double operand1, operand2;
    	private int numofoperands;
    	
        Scanner read=new Scanner(System.in);
    	String scandata, scaninput;
    	int scannumofoperands,scanoperandsindex;
    	public  String [] workarray;
    	public String [] dataarray;
    	
        public void setsize(int size)
        {
            arraysize=size;
        }
        
        public  void initialize()
        {
        	dataarray = new String [arraysize];
        	System.out.println("your array initialized with "+dataarray.length+" elements"); //+arraysize+ wrong, instead, dataarray.length
        	
        	for (int i=0;i<dataarray.length;i++)
        	{	
        		System.out.print("x["+(i+1)+"] = ");
        		scandata=read.nextLine();
        		dataarray[i]=scandata;
        		System.out.println();
        	}	
         }
        
        public  void getnumofoperands()
        {
            for (int i=0; i<dataarray.length; i++) 
            {
            	
        	     System.out.println(dataarray[i]);
        	     System.out.println("dataarray.length= "+dataarray.length+"\narraysize= "+arraysize);
        	     //System.out.println(" dgfdgfdgfdgdfgdgdgdgdgdg"+dataarray[i]);
            } // end for    
        	     
        	
            do{
            	   System.out.println("arraysize= "+arraysize+" dataarray.length= "+dataarray.length);
                   System.out.println("enter number of operands [2 operands or more] but less than or equal "+arraysize);
                   scannumofoperands = read.nextInt();
              }while(scannumofoperands < 2 || scannumofoperands > arraysize); // end do while
                           
                   	 int workarraysize = scannumofoperands;
                 	 workarray = new String [workarraysize];
                 	 
                     	 if (workarraysize==arraysize) 
                         	     System.arraycopy(dataarray, 0, workarray,0, dataarray.length); //copyfrom, int, copyto, int, num of elements)  
                             
                     	 for(int i=0;i<workarray.length;i++)
                     	 {
                     	       System.out.print("workarray contains:"+workarray[i]);   	//to chech that both must be equal 	                   	 
                     	       System.out.print("datarray contains:"+dataarray[i]);   	 	                   	 
                     	 } //end for	
                     	 
                     	 
                        	   if (workarraysize!=arraysize)
                     	       { 
                     	       	 boolean first=true;
                     	       	   System.out.println("\nworkarraysize and arraysize are NOT equal");
                     	       	   for (int i=0; i<workarray.length; i++)
                     	       	   {
                     	       	   	    do {
                     	       	   	    	 if (first)
                     	       	   	    	 {                	       	   	    	 
                     	       	   	    	 	 System.out.println("\nenter index # "+(i+1));
                     	       	   	    	 	 System.out.print("[1 to "+dataarray.length+"]");
                     	       	   	    	 	 first=false;
                     	       	   	    	 } 
                     	       	   	    	 else
                     	       	   	    	 {	 
                     	       	   	    	     System.out.println("Wrong..try again indices from workdataarray");
                            	   	             System.out.println("[1 to "+dataarray.length);
                     	       	   	    	 }
                            	   	        scanoperandsindex = read.nextInt();
                            	   	        
                     	       	   	    }while (scanoperandsindex<1 || scanoperandsindex>dataarray.length);
                     	       	   	    
                     	       	   	    first=true;
                            	   	    int operandindex = scanoperandsindex;
                            	   	    
                            	   	        if (operandindex<1)
                            	   	        {
                                                   System.out.println("you mean index number 1");               
                            	   	               scanoperandsindex=1;
                                                   workarray[i] = dataarray[scanoperandsindex-1];
                            	   	        } // end if
                            	   	              else
                            	   	              {
                            	   	                    if (operandindex>dataarray.length)
                                                        {
                                                            System.out.println("you mean index number "+dataarray.length);  
                            	   	                        scanoperandsindex=dataarray.length;
                                                            workarray[i] = dataarray[scanoperandsindex-1];
                                                        } // end if     
                                                      
                                                             else workarray[i] = dataarray[scanoperandsindex-1];                                        
                                                   } // end of els                                             
                     	       	   } // end of for
                     	       	   for (int i=0; i<workarray.length; i++) System.out.println(workarray[i]);
                     	       } //end if
                     	                      
        }
    	public static void main (String [] args)
          {
              Op obj = new Op();
              Scanner read = new Scanner (System.in);      
              String scanchoice;
              int size, choice,value;
              
              do
              {
      	          System.out.println("choose an operation: 1:+ 2:- 3:* 4:/");
                  scanchoice = read.nextLine();
                  choice = Integer.parseInt(scanchoice);
                  
    	          switch (choice)
    	             {
    		           case 1 : System.out.println("enter number of elements:");
    		                      value=read.nextInt();
    		                      obj.setsize(value);
    		                      obj.initialize();
    		                      obj.getnumofoperands();
    		                      //obj.convert;
    		                     /* pluseop(operand1,operand2);
    		           case '2' : initialize();           
    			                  subop(operand1,operand2);
                       case '3' : initialize();
            	                  mulop(operand1,operand2);
                       case '4' : initialize();
    	                          divop(operand1,operand2);*/
    	             }// end switch
    	      } while(choice!=1 || choice!=2 || choice!=3 || choice!=4); // end do-while
    	      
           }  // end main    
    } //end class
    Last edited by amrmb09; 11-20-2010 at 11:13 PM.

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

    Default

    Quote Originally Posted by amrmb09 View Post
    please help, what is the problem with the main()
    First you tell US. Again, what error messages are you getting? Also please edit your posts and use code tags so that we can read your code. The first link in my signature links will tell you how.

  10. #10
    amrmb09 is offline Member
    Join Date
    Nov 2010
    Posts
    75
    Rep Power
    0

    Default this is the error message

    --------------------Configuration: <Default>--------------------
    D:\javafiles\Op.java:102: illegal start of expression
    public static void main (String [] args)
    ^
    D:\javafiles\Op.java:102: illegal start of expression
    public static void main (String [] args)
    ^
    D:\javafiles\Op.java:102: ';' expected
    public static void main (String [] args)
    ^
    D:\javafiles\Op.java:102: '.class' expected
    public static void main (String [] args)
    ^
    D:\javafiles\Op.java:102: ';' expected
    public static void main (String [] args)
    ^
    D:\javafiles\Op.java:133: reached end of file while parsing
    } //end class
    ^
    6 errors

    Process completed.

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

    Default

    It looks like you've got your main method inside of another method which is illegal, but it's very hard to tell since your post doesn't use code tags. Again, please edit your posts above and add tags to your code. The tag

    [cod&#101;]

    goes above your block of code, and the tag

    [/cod&#101;]

    goes below your block of code. Notice that they are different.

  12. #12
    amrmb09 is offline Member
    Join Date
    Nov 2010
    Posts
    75
    Rep Power
    0

    Default hello, please guide me

    hello,
    i would like to create a method that accepts arrays as parameters and return an array as well, so,, please tell me whether the below stated java code is correct and if not, please guide me

    Java Code:
    public static String [] convertStrToInt (String [] , String [] )
    {
    .....
    .....
    .....
    return ???
    }
    Last edited by amrmb09; 11-20-2010 at 11:09 PM.

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

    Default

    Quote Originally Posted by amrmb09 View Post
    hello,
    i would like to create a method that accepts arrays as parameters and return an array as well, so,, please tell me whether the below stated java code is correct and if not, please guide me

    public static String [] convertStrToInt (String [] , String [] )
    {
    .....
    .....
    .....
    return ???
    }
    Did you at least read the first link supplied by Fubarable? I, for one, am not going to read those unformatted lumps of code. Fix that.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  14. #14
    amrmb09 is offline Member
    Join Date
    Nov 2010
    Posts
    75
    Rep Power
    0

    Default why u seem so angry

    why u seem so angry, ?????????????
    if u dont want to help just dont.
    and who told u that i'm not trying to set [\code]????????????
    or i didnt read Fubarable message??????????

    do u know what? from u i dont need any help even if ur the only one know java in this world

    and,i forget one more thing








    No kind regards for u at all
    Last edited by amrmb09; 11-20-2010 at 07:26 PM.

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

    Default

    I don't see any anger in his post and his point is valid as we would all appreciate it if you would edit your previous posts here and add code tags. It's not hard to do and would help us to help you. So why haven't you tried to do this yet? If you don't understand how, just say so.

  16. #16
    amrmb09 is offline Member
    Join Date
    Nov 2010
    Posts
    75
    Rep Power
    0

    Default ja, actually i didnt understand it

    Hello Fubarable,

    actually i tried but it was confusing for me to distinguish which line or keyword shuld be placed within the brackets.

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

    Default

    You just need to place [cod&#101;] on the top of all your code and [/cod&#101;] on the bottom, like so:

    Java Code:
    [cod&#101;]
          for (int i = 0; i < intArray.length; i++) {
             if (i == 0) {
                System.out.print(intArray[i] + ", ");
             } else {
                boolean duplicate = false;
                for (int j = i - 1; j >= 0; j--) {
                   if (intArray[i] == intArray[j]) {
                      duplicate = true;
                   }
                }
                if (!duplicate) {
                   System.out.print(intArray[i] + ", ");
                }
             }
          }
    [/cod&#101;]

  18. #18
    amrmb09 is offline Member
    Join Date
    Nov 2010
    Posts
    75
    Rep Power
    0

    Default many thanks

    Thank you Mr.Fubarable

  19. #19
    amrmb09 is offline Member
    Join Date
    Nov 2010
    Posts
    75
    Rep Power
    0

    Default

    i would like to create a method that accepts arrays as parameters and return an array as well, so,, please tell me whether the below stated java code is correct and if not, please guide me

    Java Code:
    public static String [] convertStrToInt (String [] , String [] )
    {
    .....
    .....
    .....
    return ???
    }

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

    Default

    Quote Originally Posted by amrmb09 View Post
    hello,
    i would like to create a method that accepts arrays as parameters and return an array as well, so,, please tell me whether the below stated java code is correct and if not, please guide me

    Java Code:
    public static String [] convertStrToInt (String [] , String [] )
    {
    .....
    .....
    .....
    return ???
    }
    Sure this could work as a skeleton for what you're trying to do, but the devil's in the details. Just how is the method supposed to act on the inputs? What's the logic behind what you're doing?

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 2
    Last Post: 07-02-2010, 02:20 PM
  2. Hello! and I need help. I dont know were to start
    By Fall0ut in forum New To Java
    Replies: 10
    Last Post: 05-19-2010, 06:26 PM
  3. Using libraries that others dont have(j3d)
    By scorpion9 in forum Advanced Java
    Replies: 7
    Last Post: 02-19-2010, 11:24 AM
  4. Sometimes get the right results sometimes dont
    By Battlefeldt in forum New To Java
    Replies: 0
    Last Post: 12-18-2009, 01:03 AM
  5. Replies: 6
    Last Post: 09-14-2009, 10:46 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
  •