这是Java代码,我如何显示类似示例:

public static void main(String[] args) {
    // TODO code application logic here
    int i = 1;
    int j = 1;


   for (i = 1 ; i <= 10; i++)
   {
       for (j = 1; j<= 5; j++)
       {
        if (i % 2 == 0 )
        {
            System.out.println ( j + "/5 = " + i /10.0);
            //the output should be
            // 1/5 = 0.2
            // 2/5 = 0.4
            // 3/5 = 0.6
            // 4/5 = 0.8
            // 5/5 = 1.0

        }
       }

   }

    System.out.println("--------------------");
   }

 }


我如何显示1/5 = 0.2 2/5 = 0.4 3/5 = 0.6 4/5 = 0.8 5/5 = 1.0的输出

最佳答案

您在这里做的太多了。只需执行以下操作:

public static void main(String[] args) {
     for (int i = 1; i<= 5; i++)
     {
         System.out.println ( i + "/5 = " + i / 5.0);
     }
     System.out.println("--------------------");
}


输出:

1/5 = 0.2
2/5 = 0.4
3/5 = 0.6
4/5 = 0.8
5/5 = 1.0
--------------------

07-24 09:49
查看更多