JKF 捷克論壇

搜尋
查看: 655 | 回覆: 1 | 跳轉到指定樓層
mz123468
男爵 | 2010-5-12 09:47:43

各位好
我在設計java程式時碰到一個問題
程式內容如下:

import java.util.*;

public class HomeWork
{
   public static void main(String[] args)
   {
      Scanner sc = new Scanner(System.in);
      int no1, no2, result1, result2, result3, result4;
      
      System.out.println("the first number is : ");
      no1 = sc.nextInt();
      
      System.out.println("the second number is : ");
      no2 = sc.nextInt();
      
      result1 = no1 + no2;
      result2 = no1 - no2;
      result3 = no1 * no2;
      result4 = no1 / no1;
      
      System.out.printf("no1 + no2 = %10.2f%n", result1);
      System.out.printf("no1 - no2 = %10.2f%n", result2);
      System.out.printf("no1 * no2 = %10.2f%n", result3);
      System.out.printf("no1 / no2 = %10.2f%n", result4);
   }
}


使用javac偵錯時沒有問題
但是實際卻不能執行
請問我應該怎麼修改呢
分享分享 收藏收藏
FB分享
回覆 使用道具
umin123
男爵 | 2010-5-14 23:58:12

我覺得應該是  資料格式的問題  
System.out.printf("no1 + no2 = %10.2f%n", result1);
System.out.printf("no1 - no2 = %10.2f%n", result2);
System.out.printf("no1 * no2 = %10.2f%n", result3);
System.out.printf("no1 / no2 = %10.2f%n", result4);

依照上面你寫的來看  結果是浮點數{:3_306:}

這裡有資料  你可以參考一下  http://caterpillar.onlyfun.net/G ... V1/OutputFormat.htm
引言 使用道具
您需要登入後才可以回覆 登入 | 加入會員

建議立即更新瀏覽器 Chrome 95, Safari 15, Firefox 93, Edge 94。為維護帳號安全,電腦作業系統建議規格使用Windows7(含)以上。
回頂部 下一篇文章 放大 正常倒序 快速回覆 回到列表