问答详情
源自:3-7 Java中的条件运算符

求print和println和printlf的区别

import java.util.*;

public class Main
{
public static void main(String[] args)
{
System.out.println("Hello World!");

Scanner input = new Scanner(System.in);

System.out.print("Enter a number: ");
double number1 = input.nextDouble();

System.out.print("Enter second number: ");
double number2 = input.nextDouble();

double product = number1 * number2;
System.out.printf("The product of both numbers is: %f", product);
}
}

提问者:Ocelot 2019-08-01 12:41

个回答

  • qq_宁风致
    2019-08-01 13:32:32
    已采纳

    print少了ln就不会自动换行,而println会自动换行

    而如果使用printf就要像C语言一样需要输入对应字符的字母,如int %d

    而print和println则不需要