にMath.sqrtとMath.powを使用してintに、私は次のエラーを取得していますし、それは第109に表示されている理由:(互換性のないタイプ:ダブルの可能性Loosy変換するJava
Incompatible types: possible loosy conversion from double to int
私は知りませんコードの行このコードはMath.sqrtとMath.powを使用しています
コードを:。。
total[b] = Math.sqrt(Math.pow(2, (x[b+1][b+1] - x[b][b+1])) + Math.pow(2, (x[b+2][b+2] - x[b][b+2])));
それは、単純なエラーであれば、私を割いてください、私は昨日だけでJavaを開始し、私がしようとしています。私はそれをぶら下げている。スタックオーバーフローのかなり新しいメンバー:)
ここでは私のコードです:
import java.util.Scanner;
public class twoDArray4 {
public static void main(String args[])
{
int rows;
int columns = 3;
Scanner scan = new Scanner(System.in);
System.out.print("Please enter the number of cities: ");
rows = scan.nextInt();
double x[][] = new double [rows][columns];
String name[] = new String[rows];
// --- Inputting ---
// 1st City Column Starting from 1
for (int k = 0; k < rows; k++)
{
x[k][0] = (k + 1);
}
for (int i = 0; i < rows; i++)
{
System.out.println(" ");
// Storing City Name
System.out.print("Enter City Name: ");
String names = scan.next();
name[i] = names;
// Storing Coordinates
System.out.println("Enter coordinates for " + name[i] + " by (x [enter] y): ");
for (int j = 1; j < columns; j++)
{
x[i][j] = scan.nextInt();
}
}
// --- Printing ---
// Prints Out: cityName (x, y)
System.out.println(" ");
for (int i = 0; i < rows; i++)
{
System.out.print(" ");
System.out.print(name[i] + " is on (");
for (int j = 1; j < columns; j++)
{
if (j > 1)
{
System.out.print(", ");
}
System.out.print(x[i][j]);
}
System.out.print(")");
System.out.println(" ");
}
// Prints Out Distance
System.out.println(" ");
System.out.println(" ");
// Factorial Of Rows
int z;
int num = 1;
for(z = 1;z <= rows; z++)
{
num = num * z;
}
int total[] = new int[num];
// Prints Shortest Distance
for (int b = 0; b < num; b++)
{
System.out.print("The shortest distance from " + name[b]);
System.out.println(" to " + name[b+1] + " is ");
total[b] = Math.sqrt(Math.pow(2, (x[b+1][b+1] - x[b][b+1])) + Math.pow(2, (x[b+2][b+2] - x[b][b+2])));
}
}
}
int型が移入された配列のintにdoubleを代入しています。 – Li357