Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I set a double from two integers?

Tags:

java

double

I was wondering if it's possible to set a double from two integers, say:

int i = 1;
int j = 2;

double l = i.j;

so hopefully have l set to 1.2.

I'm currently trying this with a loop, but nothing is coming of it:

for (int i = 0; i < 8; i++){
    for(int l = 0; l < 8; l++){
        double piece = i.l;
            ChessSquare chessSquare = new ChessSquare(i, l, piece);
            int[][] square = new int[i][l];
            frame.add(chessSquare);
    }
}
like image 966
JmJ Avatar asked Jan 25 '26 22:01

JmJ


2 Answers

int i=1;
int j=2;
String s = i+"."+j;
double d = Double.parseDouble(s);
System.out.println(d);

How about this? I know String concat and stuffs will be pretty annoying(exceptions mainly), but certainly, this could help you out, if i & j are for sure gonna be numbers.

like image 102
Rahul Avatar answered Jan 27 '26 12:01

Rahul


This should work, although I don't understand where a double comes into play in a chess game:

int i = 1;
int j = 2;
double piece = i + j /  Math.pow(10.0 , String.valueOf(j).length()) 
like image 34
turbo Avatar answered Jan 27 '26 12:01

turbo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!