• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

to print intege value of generic

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 24
Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try this
You are using a generics so the / operator is not defined.

 
karthik swamy
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

massimiliano cattaneo wrote:Try this
You are using a generics so the / operator is not defined.




Thanks it works fine.
 
No matter. Try again. Fail again. Fail better. This time, do it with this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic