Results 1 to 20 of 32
- 11-18-2010, 08:29 PM #1
Member
- Join Date
- Nov 2010
- Posts
- 75
- Rep Power
- 0
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
}
}
- 11-18-2010, 08:40 PM #2
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
the semicolon on the end of the line before :D
- 11-18-2010, 09:12 PM #3
Member
- Join Date
- Nov 2010
- Posts
- 75
- Rep Power
- 0
- 11-18-2010, 09:19 PM #4
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
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)
-
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!
- 11-19-2010, 02:09 PM #6
Member
- Join Date
- Nov 2010
- Posts
- 75
- Rep Power
- 0
Thank u all
many thanks for your help
- 11-19-2010, 02:49 PM #7
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:
- 11-19-2010, 10:34 PM #8
Member
- Join Date
- Nov 2010
- Posts
- 75
- Rep Power
- 0
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 classLast edited by amrmb09; 11-20-2010 at 11:13 PM.
-
- 11-20-2010, 12:30 AM #10
Member
- Join Date
- Nov 2010
- Posts
- 75
- Rep Power
- 0
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.
-
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
[code]
goes above your block of code, and the tag
[/code]
goes below your block of code. Notice that they are different.
- 11-20-2010, 03:06 PM #12
Member
- Join Date
- Nov 2010
- Posts
- 75
- Rep Power
- 0
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.
- 11-20-2010, 03:43 PM #13
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,424
- Blog Entries
- 7
- Rep Power
- 17
- 11-20-2010, 06:41 PM #14
Member
- Join Date
- Nov 2010
- Posts
- 75
- Rep Power
- 0
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 allLast edited by amrmb09; 11-20-2010 at 07:26 PM.
-
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.
- 11-20-2010, 08:10 PM #16
Member
- Join Date
- Nov 2010
- Posts
- 75
- Rep Power
- 0
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.
-
You just need to place [code] on the top of all your code and [/code] on the bottom, like so:
Java Code:[code] 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] + ", "); } } } [/code]
- 11-20-2010, 11:11 PM #18
Member
- Join Date
- Nov 2010
- Posts
- 75
- Rep Power
- 0
many thanks
Thank you Mr.Fubarable
- 11-20-2010, 11:15 PM #19
Member
- Join Date
- Nov 2010
- Posts
- 75
- Rep Power
- 0
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 ??? }
-
Similar Threads
-
Formatting java command line output - Multi line string
By dricco in forum New To JavaReplies: 2Last Post: 07-02-2010, 02:20 PM -
Hello! and I need help. I dont know were to start
By Fall0ut in forum New To JavaReplies: 10Last Post: 05-19-2010, 06:26 PM -
Using libraries that others dont have(j3d)
By scorpion9 in forum Advanced JavaReplies: 7Last Post: 02-19-2010, 11:24 AM -
Sometimes get the right results sometimes dont
By Battlefeldt in forum New To JavaReplies: 0Last Post: 12-18-2009, 01:03 AM -
FileOutputStream, I dont know what Im doing wrong...
By Addez in forum New To JavaReplies: 6Last Post: 09-14-2009, 10:46 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks