what if user doesnt know how to give input and he gives like the normal newbie who doesnt knw any programming
Cast it to a long, or use nextLong instead of nextInt, if you're reading from a Scanner on the input, or if you're using Integer.parseInt() use Long.parseLong(). As always, use a try block around nextLong() or parseLong(). If it's too big for a Long, you're stuck, but that's pretty big. They'll probably get tired before they enter all those digits.
for the record, maxLong is 9223372036854775807 - about ten digits longer than the average uesr's attention span. :)
You can get that value easily enough, if you need it:
i got a task to write a method where input is a number of any size. that's it. no limitation of data size. only thing is it's an integer number of any size. so i dnt have control over input. all i need to handle how to carry it into function
Then save it as a String and then have a method that checks if that String represents a number. Remember the value would be saved as a String.
For validation, you can take each character of that String using for loop.
Check the method charAt(int i) of the String class. Then take each character and check if it is a number using a method from the Character class.
If you find that a character from that String is not a number then display a message and don't continue with the rest of the program.
I can't imagine what it is he wants you to do. Taking it as a String would be the normal thing - as JA said, you'd take the String, validate it, and pass it back.
There isn't a primitive number type that has arbitrary capacity - that's by definition, a primitive is a fixed number of bytes. So does he want you to write a class that holds an arbitrary-length int? You'd still be taking it in as a String, but everything's a String when it comes in - nextInt() takes a String to begin with, and then converts it to an int.
So that'll be my best guess: write a wrapperclass, call it "ArbitraryInt". Constructor takes a String, declares an array of int, same length as the String, and puts digits into the array, throwing an exception if it finds a non-digit.
toString should be obvious, you could write simple arithmetic routines if you felt particularly up to it. compareTo() shouldn't be hard.
Cheesy, yes, but maybe it's what he's after. Can't think what else it might be.
[EDIT: just re-read previous post, and I think this is actually what he wants you to do. ]