小编Sam*_*sah的帖子

在 Java 类 DecimalFormat 中,小数左侧的主题标签有什么作用?

我这个问题的标题不太好,但希望我能在这篇文章中对此进行更多解释。

import java.io.*;
import java.text.*;
public class Output {
public static void main(String[] args) {

    /*double number = 438.978;
    /*UpperCase <- naming convention for classes.DecimalFormat x = new DecimalFormat("#.#");
    System.out.println(x.format(number));*/

    double number = 43.97;
    DecimalFormat x = new DecimalFormat(".###");
    System.out.println(x.format(number));

  }
}
Run Code Online (Sandbox Code Playgroud)

别介意评论。在我的 11 年级计算机科学课上,我问老师小数点左边的主题标签(第 11 行)是否对双数有任何影响,我们在课堂上尝试过,发现它并没有改变System.out.println语句。

~/workspace/Java/ $ java Output
43.97
Run Code Online (Sandbox Code Playgroud)

有人可以向我解释一下小数点左边参数的用途吗?有人编程让它做某事,所以我很好奇。

java format formatting class decimalformat

3
推荐指数
1
解决办法
1318
查看次数

在程序运行时询问用户输入?

创建一个自动化的战斗系统,但我希望用户有一些输入.问题是每当我要求输入时,整个功能都会停止,直到它从用户那里得到输入.

def EnemyAttack(TypeOfEnemy):
global raceinput
special_ability_prompt = input("") #When you make the magic classes and put them in a dictionary, append them here.
while (Player.hp > 1 and TypeOfEnemy.hp > 1):
    if (special_ability_prompt == "HeavyAttack()"):
        if (raceinput == "CAVE"):
            TypeOfEnemy.hp = TypeOfEnemy.hp - (Player.atk / 2)
            print("You use a Heavy Attack! The ",TypeOfEnemy.name," takes ",(Player.atk / 2), " damage!")
            time.sleep(Player.atkrate * 1.5)
        else:
            TypeOfEnemy.hp = TypeOfEnemy.hp - (Player.atk / 5)
            print("You use a Heavy Attack! The ",TypeOfEnemy.name," takes ",(Player.atk / …
Run Code Online (Sandbox Code Playgroud)

python class input python-3.x

0
推荐指数
1
解决办法
41
查看次数

标签 统计

class ×2

decimalformat ×1

format ×1

formatting ×1

input ×1

java ×1

python ×1

python-3.x ×1