aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes to print intege value of generic Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "to print intege value of generic" Watch "to print intege value of generic" New topic
Author

to print intege value of generic

karthik swamy
Ranch Hand

Joined: Mar 14, 2011
Posts: 42
hello all'
i am using generics and here is the code:

public class generics {
public static <E> void printArray(E[] inputArray){
for(E element:inputArray){
Integer i=element/10; //error line
System.out.printf("%s ",i);
}
System.out.println();
}
public static void main(String ...args){
Integer[] array={10,20,30,40,50,60,70,80,90,100};
System.out.println("The array contains: ");
printArray(array);
System.out.println("hello world");

}
}

if i didnt use that error line that it gives the desired output
but if i use that line it gives error that : The operator / is undefined for the argument type(s) E, int

and i need to display 1 2 3 4 5 6 7 8 9 10

so please tell me where i a wrong..

thanks
karthik swamy.
massimiliano cattaneo
Greenhorn

Joined: Jun 30, 2011
Posts: 24

Try this
You are using a generics so the / operator is not defined.



[SCJP 6.0 88%] [OCPJBCD 6.0 96%] [OCPJWCD 6.0 87%]
karthik swamy
Ranch Hand

Joined: Mar 14, 2011
Posts: 42
massimiliano cattaneo wrote:Try this
You are using a generics so the / operator is not defined.




Thanks it works fine.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: to print intege value of generic