I want to take Input from the user as Big-Integer and manipulate it into a For loop
BigInteger i;
for(BigInteger i=0; i<=100000; i++) {
System.out.println(i);
}
But it won’t work
can any body help me.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You use these syntax instead:
So here’s an example of putting it together:
Note that using
BigIntegeras a loop index is highly atypical.longis usually enough for this purpose.API links
java.math.BigIntegerint compareTo(BigInteger val)frominterface Comparable<T>BigInteger subtract(BigInteger val)BigInteger add(BigInteger val)static BigInteger valueOf(long val)The
compareToidiomFrom the documentation:
In other words, given
BigInteger x, y, these are the comparison idioms:This is not specific to
BigInteger; this is applicable to anyComparable<T>in general.Note on immutability
BigInteger, likeString, is an immutable object. Beginners tend to make the following mistake:Since they’re immutable, these methods don’t mutate the objects they’re invoked on, but instead return new objects, the results of those operations. Thus, the correct usage is something like: