我正在运行以下Perl脚本:
#!/usr/bin/env perl
$file1 = $ARGV[0];
system("analyze $file1 M | grep Moments -A 4 > inertia.dat");
open(INFILE, "inertia.dat") or die "Can't open file: $!";
$line = <INFILE>;
$line = <INFILE>;
$line = <INFILE>;
$line = <INFILE>;
$line = <INFILE>;
$I1 = substr($line,16,12);
$line = <INFILE>;
$I2 = substr($line,16,12);
$line = <INFILE>;
$I3 = substr($line,16,12);
$line = <INFILE>;
if (($I1>$I2) && ($I1>$I3)) {$I1 = <Imax>;}
if (($I2>$I1) && ($I2>$I3)) {$I2 = <Imax>;}
if (($I3>$I1) && ($I31>$I2)) {$I3 = <Imax>;}
if (($I1<$I2) && ($I1<$I3)) {$I1 = <Imin>;}
if (($I2<$I1) && ($I2<$I3)) {$I2 = <Imin>;}
if (($I3<$I1) && ($I3<$I2)) {$I3 =<Imin>;}
$delta = ((<Imax>)-(<Imin>))/(<Imax>);
print "$I1 $I2 $I3\n";
close INFILE;
当我运行该文件时,我会在第45行&#34;
非法划分为零;第45行
$delta = ((<Imax>)-(<Imin>))/(<Imax>);
inertia.dat文件的一个示例是:
惯性和主轴的时刻:
Moments (amu Ang^2) X-, Y- and Z-Components of Axes
102508.853 0.096680 0.000809 -0.995315
114243.409 0.393377 -0.918614 0.037464
118155.898 -0.914280 -0.395156 -0.089130
答案 0 :(得分:6)
首先,Imax
位于您编写的每个perl脚本的顶部。这将告诉您第二个问题:
其次,你试图从名为Imin
和import java.util.Scanner ;
public class Proj
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
int S1 = 0 ;
String option =null;
int[][] MT = new int[S1][S1];
System.out.println("Welcome To The Multiplication Table Program!");
do{
System.out.print("Input a number from 1-20: ") ;
String Num =input.nextLine();
if (Num.equals ("1")){
S1 = 1 ; MT = timesTable(1,1) ;
}
else if (Num.equals ("2")){
S1 = 2 ; MT = timesTable(2,2) ;
}
else if (Num.equals ("3")){
S1 = 3 ;
MT = timesTable(3,3) ;
}
else if (Num.equals ("4")){
S1 = 2 ;
MT = timesTable(4,4) ;
}
else if (Num.equals ("5")){
S1 = 2 ;
MT = timesTable(5,5) ;
}
else if (Num.equals ("6")){
S1 = 2 ;
MT = timesTable(6,6) ;
}
else if (Num.equals ("7")){
S1 = 2 ;
MT = timesTable(7,7) ;
}
else if (Num.equals ("8")){
S1 = 2 ;
MT = timesTable(8,8) ;
}
else if (Num.equals ("9")){
S1 = 2 ;
MT = timesTable(9,9) ;
}
else if (Num.equals ("10")){
S1 = 2 ;
MT = timesTable(10,10) ;
}
else if (Num.equals ("11")){
S1 = 2 ;
MT = timesTable(11,11) ;
}
else if (Num.equals ("12")){
S1 = 2 ;
MT = timesTable(12,12) ;
}
else if (Num.equals ("13")){
S1 = 2 ;
MT = timesTable(13,13) ;
}
else if (Num.equals ("14")){
S1 = 2 ;
MT = timesTable(14,14) ;
}
else if (Num.equals ("15")){
S1 = 2 ;
MT = timesTable(15,15) ;
}
else if (Num.equals ("16")){
S1 = 2 ;
MT = timesTable(16,16) ;
}
else if (Num.equals ("17")){
S1 = 2 ;
MT = timesTable(17,17) ;
}
else if (Num.equals ("18")){
S1 = 2 ;
MT = timesTable(18,18) ;
}
else if (Num.equals ("19")){
S1 = 2 ;
MT = timesTable(19,19) ;
}
else if (Num.equals ("20")){
S1 = 2 ;
MT = timesTable(20,20) ;
}
else System.out.println("Error! Input a number from 1-20 only!") ;
for(int row = 0; row < MT.length ; row++)
{
for (int column = 0; column < MT[row].length; column++)
{
System.out.printf("%3d ",MT[row][column]);
}
System.out.println();
}
System.out.println("Enter 'Y' to enter another number \nEnter 'N' to exit ") ;
do{
System.out.print("Y/N: ");
option = input.nextLine() ;
if (option.equals ("Y"))
{
S1 = 0 ; MT = timesTable(0,0) ;
}
else if (option.equals ("N") )
System.out.println("Thank you for using the program!") ;
else System.out.println("Enter Y or N only!") ;
} while (option.equals("N")) ;
} while (option.equalsIgnoreCase("Y")) ;
}
public static int[][] timesTable(int r, int c)
{
int [][] TT = new int[r][c];
for (int row = 0; row < TT.length ; row++)
{
for (int column = 0; column < TT[row].length; column++)
{
TT[row][column] = (row+1)*(column+1);
}
}
return TT;
}
}
的文件句柄中读取,所以你当然会得到一个被零除(或者更确切地说,是未定义的,正在被转换为在这种情况下为零)。脚本中不存在这些文件句柄。