「如何利用java输入姓名」如何利用java输入姓名
本篇文章给大家谈谈如何利用java输入姓名,以及如何利用java输入姓名对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
- 1、编写一个JAVA程序 输入自己的姓名和年龄并输出 怎么写
- 2、java如何输入名字
- 3、java程序设计,用scanner编写,输入姓名,性别,年龄,住址,婚否,可以输出相应的数据?
- 4、在Java中如何让用户在界面输入姓名,住址,电话
- 5、java输入学生姓名如何编写
编写一个JAVA程序 输入自己的姓名和年龄并输出 怎么写
在main里写
String name;
String age;
Scanner sc=new Scanner(System.in);
System.out.println("输入姓名");
name=sc.nextLine();
System.out.println("输入年龄");
age=sc.nextLine();
System.out.println("姓名"+name);
System.out.println("年龄"+age);
sc.close();
扩展资料:
JAVA程序的语言特点:
1.简单性
Java看起来设计得很像C++,但是为了使语言小和容易熟悉,设计者们把C++语言中许多可用的特征去掉了,这些特征是一般程序员很少使用的。例如,Java不支持go to语句,代之以提供break和continue语句以及异常处理。
Java还剔除了C++的操作符过载(overload)和多继承特征,并且不使用主文件,免去了预处理程序。因为Java没有结构,数组和串都是对象,所以不需要指针。
Java能够自动处理对象的引用和间接引用,实现自动的无用单元收集,使用户不必为存储管理问题烦恼,能更多的时间和精力花在研发上。
2.面向对象
Java是一个面向对象的语言。对程序员来说,这意味着要注意应中的数据和操纵数据的方法(method),而不是严格地用过程来思考。在一个面向对象的系统中,类(class)是数据和操作数据的方法的集合。
数据和方法一起描述对象(object)的状态和行为。每一对象是其状态和行为的封装。类是按一定体系和层次安排的,使得子类可以从超类继承行为。在这个类层次体系中有一个根类,它是具有一般行为的类。Java程序是用类来组织的。
java如何输入名字
public class Demo {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
System.out.println("请输入你的名字:");
String name=scanner.next();
System.out.println("请输入你的体重:");
float weight=scanner.nextFloat();
System.out.println("请输入你的身高:");
float height=scanner.nextFloat();
System.out.println("姓名:"+name+"\t"+"体重:"+weight+"\t"+"身高:"+height);
System.out.println("标准:"+(height-105));
}
}
java程序设计,用scanner编写,输入姓名,性别,年龄,住址,婚否,可以输出相应的数据?
package test;
import java.util.Scanner; // Import the Scanner class
public class Test{
public static void main(String[] args) {
Scanner myObj = new Scanner(System.in); // Create a Scanner object
System.out.print("输入年龄:");
String age= myObj.nextLine(); // Read user input
System.out.print("输入姓名:");
String name= myObj.nextLine(); // Read user input
//再写 地点。。。
System.out.println(name+" 你好,今年" + age+"岁"); // Output user input
}}
在Java中如何让用户在界面输入姓名,住址,电话
import java.io.*;
public class FileIn {
public static void main(String []args) throws IOException {
String name;
String address;
String q = null;
File f=new File("C:\\Users\\Media\\Desktop","file.txt");
//BufferedWriter fout=new BufferedWriter(new FileWriter(f));
FileWriter fout = new FileWriter(f, true);
//BufferedWriter fout = new BufferedWriter(new OutputStreamWriter(
//new FileOutputStream(f, true)));
//PrintStream fout=new PrintStream(new FileOutputStream(f));
//System.setOut(fout);
fout.write("fasfas");
fout.flush(); //每次写入数据必须加filewriter.flush(),才能及时更新文件!!!!
Scanner sc=new Scanner(System.in);
while(true){
System.out.println("请依次输入姓名与地址:");
name=sc.nextLine();
if("quit".equals(name)){
fout.close();sc.close();System.exit(0);
}
else{
fout.write(name);
fout.flush();
}
address=sc.nextLine();
if("quit".equals(address))
{fout.close();sc.close();System.exit(0);}
else{
fout.write(address);
fout.flush();
}
}
}
}
java输入学生姓名如何编写
/*请编写程序实现学生选课界面,要求:
1.通过文本行输入学生姓名,通过单选按钮选择性别,通过复选框选择课程,并在文本框中显示所填写及选择的信息;
2.其界面如右图所示;
3.用Swing组件实现。*/
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.text.*;
public class CourseSel extends JFrame
{
private JLabel nameJLabel, sexJLabel, courseNameJLabel;
private JTextField nameJTextField;
private JRadioButton maleJRadioButton, femaleJRadioButton;
private JCheckBox cppJCheckBox, javaJCheckBox;
private JTextArea stuInfoJTextArea;
private JButton okJButton, cancelJButton;
private ButtonGroup sexButtonGroup;
private void cancelJButtonActionPerformed(ActionEvent event)
{
nameJTextField.setText("");
maleJRadioButton.setSelected(false);
femaleJRadioButton.setSelected(false);
stuInfoJTextArea.setText("");
cppJCheckBox.setSelected(false);
javaJCheckBox.setSelected(false);
}
private void okJButtonActionPerformed(ActionEvent event)
{
stuInfoJTextArea.setText("");
stuInfoJTextArea.append("姓名:\n");
if(nameJTextField.equals(""))
{
JOptionPane.showMessageDialog(null,
"请输入姓名",
"没有输入姓名",
JOptionPane.ERROR_MESSAGE);
return;
}
stuInfoJTextArea.append(nameJTextField.getText() + "\t");
if(!maleJRadioButton.isSelected() !femaleJRadioButton.isSelected())
{
JOptionPane.showMessageDialog(null,
"请输入性别",
"没有输入性别",
JOptionPane.ERROR_MESSAGE);
return;
}
if(maleJRadioButton.isSelected())
{
stuInfoJTextArea.append("男"+ "\t");
}
else
{
stuInfoJTextArea.append("女"+ "\t");
}
if(!cppJCheckBox.isSelected() !javaJCheckBox.isSelected() )
{
JOptionPane.showMessageDialog(null,
"选择课程",
"没有选课",
JOptionPane.ERROR_MESSAGE);
return;
}
if(cppJCheckBox.isSelected())
{
stuInfoJTextArea.append(cppJCheckBox.getText()+"\n");
}
if(javaJCheckBox.isSelected())
{
stuInfoJTextArea.append(javaJCheckBox.getText()+"\n");
}
}
private void createInterface()
{
Container contentPane = getContentPane();
contentPane.setLayout(null);
nameJLabel = new JLabel();
nameJLabel.setBounds(20, 20, 80, 40);
nameJLabel.setText("姓名");
contentPane.add(nameJLabel);
nameJTextField = new JTextField();
nameJTextField.setBounds(120, 20, 360, 40);
nameJTextField.setText("");
contentPane.add(nameJTextField);
sexJLabel = new JLabel();
sexJLabel.setBounds(20, 60, 80, 40);
sexJLabel.setText("性别");
contentPane.add(sexJLabel);
sexButtonGroup = new ButtonGroup();
maleJRadioButton = new JRadioButton();
maleJRadioButton.setText("男");
maleJRadioButton.setBounds( 120, 60, 80, 40);
contentPane.add(maleJRadioButton);
sexButtonGroup.add(maleJRadioButton);
femaleJRadioButton = new JRadioButton();
femaleJRadioButton.setText("女");
femaleJRadioButton.setBounds( 220, 60, 80, 40);
contentPane.add(femaleJRadioButton);
sexButtonGroup.add(femaleJRadioButton);
courseNameJLabel = new JLabel();
courseNameJLabel.setText("课程");
courseNameJLabel.setBounds( 20, 100, 80, 40);
contentPane.add(courseNameJLabel);
cppJCheckBox = new JCheckBox();
cppJCheckBox.setText("C语言");
cppJCheckBox.setBounds(120, 140, 80, 40);
contentPane.add(cppJCheckBox);
javaJCheckBox = new JCheckBox();
javaJCheckBox.setText("Java语言");
javaJCheckBox.setBounds(120, 180, 180, 40);
contentPane.add(javaJCheckBox);
okJButton = new JButton();
okJButton.setText("确定");
okJButton.setBounds(210, 260, 40, 40);
contentPane.add(okJButton);
okJButton.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
okJButtonActionPerformed(event);
}
}
);
cancelJButton = new JButton();
cancelJButton.setText("取消");
cancelJButton.setBounds(250, 260, 40, 40);
contentPane.add(cancelJButton);
cancelJButton.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
cancelJButtonActionPerformed(event);
}
}
);
stuInfoJTextArea = new JTextArea();
stuInfoJTextArea.setBounds(20, 300, 460, 240);
stuInfoJTextArea.setEditable(false);
contentPane.add(stuInfoJTextArea);
setTitle("选课系统");
setVisible(true);
setSize(500, 600);
}
CourseSel()
{
createInterface();
}
static public void main(String[] args)
{
CourseSel app = new CourseSel();
app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
关于如何利用java输入姓名和如何利用java输入姓名的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。