当前位置: 首页 > 知识库问答 >
问题:

Java程序:如何显示正确的支付金额?

秦才
2023-03-14
    import java.text.DecimalFormat;

import java.util.Scanner;

public class PENNIES {

       public static void main(String[] args)
    {

  Scanner keyboard = new Scanner (System.in);
  DecimalFormat formatter = new DecimalFormat("0.00");

    int day, DaysWorked; double finalsalary, currentpay; 


    finalsalary = 0;
    currentpay = 0.01;


    System.out.println("How many days did you work?");
    DaysWorked = keyboard.nextInt();

    if (DaysWorked < 1)
{System.out.println("Invalid input: " + DaysWorked + ", please try again!");

    }

    System.out.println("Days Worked                         Money Earned");
    System.out.println("_______________________________________________");



    for (day = 1; day <= DaysWorked; day++)
    {
      currentpay = currentpay * 2;
      System.out.println(  day + "\t \t \t \t" + currentpay);
      finalsalary += currentpay;

    }
System.out.println("Your total salary is  \n $" + formatter.format (+ finalsalary));



  }

这是我的最后一个节目,谢谢大家:

import java.text.NumberFormat; //Formats the decimal (cents)
import java.util.*;

public class PENNIES 
{

   public static void main(String[] args)
   {
    int day, DaysWorked, run = 0; double finalsalary, currentpay;  
    do {
    Scanner keyboard = new Scanner (System.in);
    NumberFormat AmericanMoney = NumberFormat.getCurrencyInstance(Locale.US); //Converts final salary into US dollars

    finalsalary = 0;
    currentpay = 0.01;

    System.out.println("How many days did you work?");
    DaysWorked = keyboard.nextInt();

    if (DaysWorked < 1){ //User cannot input less than 1 day
    System.out.println("Invalid input: " + DaysWorked + ", please try again!");

    }

    System.out.println("Days Worked                      Money Earned"); //Displays a table with results
    System.out.println("_______________________________________________");



    for (day = 1; day <= DaysWorked; day++) //Loops the currentpay with the respective day of work
    {      
      System.out.println(  day + "\t \t \t \t" + currentpay);
      finalsalary += currentpay;      
      currentpay = currentpay * 2;

    }
    System.out.println("Your total salary is  \n " + AmericanMoney.format (+ finalsalary) + "\n");

    }
    while (run < 1); //Restarts the program automatically



 }

 }

共有1个答案

葛阳
2023-03-14
currentpay = 0.01;
currentpay = currentpay * 2;
System.out.println(  day + "\t \t \t \t" + currentpay);
System.out.println(  day + "\t \t \t \t" + currentpay);
finalsalary += currentpay;
currentpay = currentpay * 2;
 类似资料:
  • 商家支付回调接口 url POST http://callback_url 回调参数说明 参数 类型 描述 uid string 百度用户ID order_id string 百度网盘订单号 third_order_id string 业务方订单号 pay_no string 支付流水号 pay_time int 支付时间 ts int 当前时间戳 sign string 签名参数(对以上参数按照

  • 同公众号支付

  • 说明 支付宝小程序支付交易SDK。 官方文档:https://opendocs.alipay.com/open/204/105465/ 类 请求参数类 APP支付参数 类名:\Yurun\PaySDK\AlipayApp\MiniApp\Params\Pay\Request 属性 名称 类型 说明 $method string 接口名称 $notify_url string 支付宝服务器主动通知商

  • 当我从文件导入字体时,它显示得很奇怪。它应该说“测试”,但它只是说“_”。 这是我的代码:

  • 我有一个,我需要在其中显示孟加拉语文本,例如: বাংলাদেশ 但是我只能看到长方形的盒子。我怎么才能正确地展示孟加拉文字呢?

  • @megalo/target 的 platform 设置成 alipay,mini-css-extract-plugin 提取文件后缀改成支付宝小程序的 acss。 const createMegaloTarget = require( '@megalo/target' ) const compiler = require( '@megalo/template-compiler' ) const