如何在java中打印多个变量行 [英] How to print multiple variable lines in java

查看:311
本文介绍了如何在java中打印多个变量行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Java中的打印行内打印webdriver测试中使用的测试数据

I'm trying to print the test data used in webdriver test inside a print line in Java

我需要在一个类中打印一个类中使用的多个变量code> system.out.print function(printf / println / whatever)。

你能帮助我吗?

I need to print multiple variables used in a class inside a system.out.print function (printf/println/ whatever).
Can you guys help me?

public String firstname;
public String lastname;

firstname = "First " + genData.generateRandomAlphaNumeric(10);
driver.findElement(By.id("firstname")).sendKeys(firstname);

lastname = "Last " + genData.generateRandomAlphaNumeric(10);
driver.findElement(By.id("lastname")).sendKeys(lastname);

我需要打印声明中的那些打印为:

名字:(我使用的变量值)

姓氏:(我使用的变量值)

I need those print in a print statement as:
First name: (the variable value I used)
Last name: (the variable value I used)

使用类似下面的内容给出了确切的结果。

但是我需要减少 printf 行的数量并使用更有效的方式。

Using something like below gives the exact result.
But I need to reduce the number of printf lines and use a more efficient way.

System.out.printf("First Name: ", firstname);
System.out.printf("Last Name: ", lastname);

谢谢!

推荐答案

你可以用1 printf

System.out.printf("First Name: %s\nLast Name: %s",firstname, lastname);

这篇关于如何在java中打印多个变量行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆