🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: aus.computers.java
2 messages
2 total messages Started by Livio Colbertaldo Sat, 21 Oct 2000 00:00
Help Needed please
#330
Author: Livio Colbertaldo
Date: Sat, 21 Oct 2000 00:00
19 lines
1035 bytes
i have this peice of code when i adjust the values n1 and e1 to bigger
values all i get on the result is 0
can neone please tell me what im doin wrong and how to fix it
thank you
public String ab1() {
 double n1,e1,s7;
 int s2;
 Integer ab3;
 String s5=new String();
n1=1000;
e1=1000;
s2=97;

 s7=Math.pow(s2,e1)%n1;
 ab3=new Integer(new Double(s7).intValue());
 s5=ab3.toString();
 return s5;;

}
Re: Help Needed please
#336
Author: Tobias Brummund
Date: Mon, 23 Oct 2000 00:00
48 lines
1594 bytes
Livio Colbertaldo wrote:
> 
> i have this peice of code when i adjust the values n1 and e1 to bigger
> values all i get on the result is 0
> can neone please tell me what im doin wrong and how to fix it
> thank you
> public String ab1() {
>  double n1,e1,s7;
>  int s2;
>  Integer ab3;
>  String s5=new String();
> n1=1000;
> e1=1000;
> s2=97;
> 
>  s7=Math.pow(s2,e1)%n1;
>  ab3=new Integer(new Double(s7).intValue());
>  s5=ab3.toString();
>  return s5;;
> 
> }

Hello !

I think this code will do what you want:

public String ab1()
{
  int n1=1000 ,e1=1000;
  BigInteger s1 = new BigInteger(97+"");
  BigInteger bi;
  bi = s1.modPow(new BigInteger(e1+""), new BigInteger(n1+""));
  return bi+"";
}

You must import java.math.*

Your problem was that you exceeded the range of double and int.

+"" is equal to .toString()

Greetings,
Tobias Brummund
-- 
______________________________________________
Wasserpflanzen & japanische Wasserfl�he unter:

  http://www-public.tu-bs.de:8080/~y0008601
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads