Java语言的简单输入输出

来源:互联网 发布:mac 应用程序图标 编辑:程序博客网 时间:2024/05/18 00:04

1.应用 System.out.printf()的方法进行格式化输出

%s c d f b 等

2.应用Scanner类进行输入

import java.util.Scanner;

Scanner input=new Scanner(System.in);

int firstNumber=input.nextInt(); //接受第一个整数

3,利用对话框进行输入和输出

import javax.swing.JOptionPane;

String firstNumber=JOptionPane.showInputDialog("请输入第一个数");

number1=Integer.parseInt(firstNumber);

JOptionPane.showMessageDialog(null,"结果是"+sub,"结果",JOptionPane.PLAIN_MESSAGE);

System.exit(0);


原创粉丝点击