使用System.print打印错误

时间:2018-06-25 17:26:14

标签: printing system

我正在尝试将每一个单独打印一行。例如它应该这样出来。

Name:
Phone: 
Car: 
Type of Work:

但是由于某种原因,它像这样出现

Name:
Phone: Car:

代码如下:

    System.out.print("  Name:");
    String name = input.next();
    System.out.print("  Phone:");
    String phone = input.next();
    System.out.print("  Car:");
    String car = input.next();
    System.out.print("  Type of work:");
    String work = input.next();
  }
}

我尝试更改System.out.println,但它不允许您在同一行上输入输入,它会自动将您跳到下一行

1 个答案:

答案 0 :(得分:0)

模拟println但在输入后应该可以使用。

public class MyClass {
    public static void main(String args[]) {
        System.out.println("  Name:");
        String work = input.next();
        System.out.print("\n");
        System.out.println("  Phone:");
        String work = input.next();
        System.out.print("\n");
        System.out.println("  Car:");
        String work = input.next();
        System.out.print("\n");
        System.out.println("  Type of work:");
    }
}

enter image description here