编写与 Fortran 程序等效的 Java 程序

发布于 2024-12-06 04:11:44 字数 529 浏览 0 评论 0原文

我在 fortran 中有类似的东西。

20:  call TESTBEGIN(a,b,c)
      if(c<1) goto 40
30:  call TESTMIDDLE(e,f,g)
      if(g==1) goto 20
40:  return        

但我的代码是这样的

   Subroutine testCase()
20:   CALL beginTest(a,b)
     IF (b.EQ.-1) GOTO 999
30:   CALL middleTest(c,b)
       IF (b.EQ.-1) GOTO 20
40:   CALL endTest(d,b)
     IF (b.EQ.-1) GOTO 30
     CALL  LastTest(e,b)
      IF (.b.EQ.-1) GOTO 40
      DO I =1,j
      DTEMP(j)=1.0
     END DO
some code
999:return

I have something like this in fortran.

20:  call TESTBEGIN(a,b,c)
      if(c<1) goto 40
30:  call TESTMIDDLE(e,f,g)
      if(g==1) goto 20
40:  return        

But my code is like this

   Subroutine testCase()
20:   CALL beginTest(a,b)
     IF (b.EQ.-1) GOTO 999
30:   CALL middleTest(c,b)
       IF (b.EQ.-1) GOTO 20
40:   CALL endTest(d,b)
     IF (b.EQ.-1) GOTO 30
     CALL  LastTest(e,b)
      IF (.b.EQ.-1) GOTO 40
      DO I =1,j
      DTEMP(j)=1.0
     END DO
some code
999:return

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

美煞众生 2024-12-13 04:11:44

类似的事情?

do
{
    c = TESTBEGIN(a,b);
    if (c < 1) break;
    g = TESTMIDDLE(e,f);
} while ( g == 1 );

对于第二个代码片段,尝试使用状态机:

for(int state = 1; state != 0; )
{
  switch(state)
  {
  case 1:
    state = (beginTest(a) == -1) ? 0 : 2;
    break;
  case 2:
    state = (middleTest(c) == -1) ? 1 : 3;
    break;
  case 3:
    state = (endTest(d) == -1) ? 2 : 4;
    break;
  case 4:
    state = (lastTest(e) == -1) ? 3 : 5;
    break;
  }
  case 5:
    state = 0;
//   DO I =1,j // Honestly I don't know what does it do.
//      DTEMP(j)=1.0
    break;
}

或者更好地尝试重新考虑算法,我认为您可以使用 Java 使其更容易阅读和理解。

Something like that?

do
{
    c = TESTBEGIN(a,b);
    if (c < 1) break;
    g = TESTMIDDLE(e,f);
} while ( g == 1 );

For the second code snippet try a state machine:

for(int state = 1; state != 0; )
{
  switch(state)
  {
  case 1:
    state = (beginTest(a) == -1) ? 0 : 2;
    break;
  case 2:
    state = (middleTest(c) == -1) ? 1 : 3;
    break;
  case 3:
    state = (endTest(d) == -1) ? 2 : 4;
    break;
  case 4:
    state = (lastTest(e) == -1) ? 3 : 5;
    break;
  }
  case 5:
    state = 0;
//   DO I =1,j // Honestly I don't know what does it do.
//      DTEMP(j)=1.0
    break;
}

Or better try to reconsider the algorithm, I think you could do it more easy to read and understand using Java.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文