- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 printf 函数创建摄氏度到华氏度的转换表。
在我的笔记中,我发现我应该能够在 printf 的 % 之后使用 ^ 标志将输出居中。但是,当我运行该程序时,Netbeans 总是给我一条错误消息。
我想知道是否有人可以帮助我集中我的输出。我的代码如下。
我已经浏览了已经回答的问题。然而,它们与我迄今为止在类里面学到的内容并不相符,因此 - 我无法使用它。
任何帮助将不胜感激。
public class CelsToFahrTable {
/**
* Main argument prints a Celsius to Fahrenheit conversion table
* using integer Celsius degrees from 0 to 40
*/
public static void main(String[] args)
{
// declare variables
double Cels; //control variable (Celsius Temperature)
System.out.printf("%10s\t%10s%n", "Celsius", "Fahrenheit");
//prints headers Celsius and Fahrenheit at the top to signify what the data
//below means. Celsius should take up 10 columns then tab to Fahrenheit
//which again takes up 10 columns
for ( Cels = 0; Cels <= 40; Cels++)
//creates count-controlled loop using for statement
//Cels initialized to 0, continues expression until 40 and increments
//by 1 degree each time
System.out.printf("%10.0f%10.1f%n", Cels, 1.8*Cels+32.0);
//creates table showing Celsius temperature followed by its corresponding
//Fahrenheit temperature. Celsius temp is 10 columns with no decimals.
//Fahrenheit temp is 10 columns with a 1 decimal precision.
//Note: I tried to center each field using "^" but it gave me an error
//every time
}//end main
“^”将放在最后:
System.out.printf ("%^10.0f%^10.1f%n", Cels, 1.8*Cels+32.0"
----但是,当我键入该代码时,我在 Netbeans 中收到错误。
最佳答案
如果你查看Formatter
javadoc,Java没有将printf的输出居中的标志,并且没有^
标志。
您的笔记可能指的是 Lava library ,它附带了 C printf 函数的“高级”Java 端口。正如 Lava specification 中所指定的那样在标志部分下,^
是居中输出的标志。
正如 SO 中其他地方所指定的,您可以使用 StringUtils.center方法来自 Apache Commons Lang Library ,或设计a method of your own .
关于java - COMP SCI 101 - 使用 Printf 将字段居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19081329/
我正在从事从大型机到 Hadoop 的迁移,并且对 Java 非常了解。我有一个 cobol 平面文件,其中包含计算字段(COMP、COMP-1、COMP-2)。我必须在 Java 应用程序中使用这个
我在使用 comp 类型的组件 (VCLZip) 中有一个事件,但要将结果显示为字符串,我想我需要将 comp 值转换为 int64,但我找不到这样做的方法。 有没有办法将 comp 值转换为 int
我正在从我的 Java 应用程序调用使用 COBOL 创建的 DB2 存储过程。 输入宏(类型 varchar): 01 SP1-INPUTS. 05 FIELD-1 PIC X(0
在vue中使用动态组件时,我们可以使用component或 html 标签,例如 div作为标签名称: 或者: // assume that the root tag of comp-name is
我有一个 EBCDIC 平面文件要从大型机处理成 C 模块。将 COMP 和 COMP-3 值转换为可读值的好过程是什么?对于 COMP-3,我是否必须将 ebcdic 字符转换为 ascii 然后十
我已将代码部署在 Windows 环境的本地计算机上的 Tomcat 6.0.32 中。同样的WAR文件部署在Linux环境下远程机器的Tomcat 7.0.39中。 context.xml的代码如下
我想做的是在一段时间后更新我的数据库。所以我正在使用 java 调度程序和连接池。我不知道为什么,但我的代码只能工作一次。它将打印: init success success javax.naming
我有一个包含许多模块的 Java EE 应用程序。我正在尝试能够进行间接 JNDI 查找。 我按照以下步骤操作: ejb-jar.xml: 在每个模块中。我定义了一个企业bean。模块中的所有DAO都
我在 sort() 函数中使用了 lambda 函数。在我的 lambda 函数中,如果两个相等,我将返回 true。然后我得到了段错误。 审核后C++ Compare , 它说 For all a,
我正在运行一个使用 COMPS 实现的应用程序,我在应用程序标准输出中收到以下错误。 ... [(2016-07-27 11:47:34,255) API] - No more tas
假设我有一个需要两个参数的函数,并且参数的顺序会影响结果。 是否可以将第一个参数传递给 partial 或 comp 函数,然后将另一个参数传递给它,如下所示: (defn bar [arg1 arg
4Clojure Problem 58表述为: 编写一个允许您创建函数组合的函数。参数列表应采用可变数量的函数,并创建一个从右到左应用它们的函数。 (= [3 2 1] ((__ rest rever
感谢您帮我看这个,这是我的问题: 我的 MyFrame 类中的 If 语句说“MyShape 是抽象的,无法实例化”我也不知道如何完成我的 actionlistener,以便它创建一个我从 jmenu
我是 C++ 的新手,我正在尝试使用 std::sort 函数对解决方案的 vector 进行排序。 代码是这样的(解决方案列表是一个* vector ): void SolutionSet::sor
我正在尝试编写一个程序来比较 2 个文件并返回它们是否相等。 我只能使用函数:fork、dup、dup2、open、write 、exec 和 read。 当我在 linux gcc 上编译程序时,它
我已经从http://www.bsc.es/computer-sciences/grid-computing/comp-superscalar/downloads-and-documentation
关闭。这个问题需要details or clarity .它目前不接受答案。 想改进这个问题吗? 通过 editing this post 添加细节并澄清问题. 关闭 6 年前。 Improve t
这个问题在这里已经有了答案: What does java:comp/env/ do? (3 个回答) 关闭去年。 java:comp/env 是什么意思? 看起来像什么: Context envCo
我正在尝试根据数组中的值对数组进行排序。我试过以下方法 function comp($a, $b) { return strcmp($a["name"], $b["name"]); }
我有部署到 glassfish 的 .war 应用程序。我想做 CDI,所以我需要从我的 POJO 中查找 java:comp/BeanManager。但它不起作用:根本找不到 BeanManager
我是一名优秀的程序员,十分优秀!