本文目录一览:
用java写一个程序,用变量保存自己的个人信息,并且输出
import java.util.Scanner;
public class 个人信息
{
public static void main(String[] args)
{
System.out.println("\n\t\t==========简单的个人信息录入==========\n");
init();
}//初始化!
private static void init()
{
/*int a1 = 073;
long b1 = 0xa38f;
System.out.println(a1+"....."+b1);*/
for (; ; )
{
System.out.println("请输入姓名:");
String a=Input.getName();
System.out.println("请输入年龄:");
int b=Input.getAge();
System.out.println("请输入学历:");
String c=Input.getEducation();
System.out.println("你输入的信息^_^\t名字:"+a+" 年龄:"+b+" 学历:"+c+"\n");
}
}
}
class Input
{
private static Scanner sc=new Scanner(System.in);
private Input(){}
static String getName()
{
String name=sc.next();
return name;
}
static int getAge()
{
int age=sc.nextInt();
return age;
}
static String getEducation()
{
String education=sc.next();
return education;
}
}
Java实现简单个人信息录入
数据库就要你自己建了.
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class PersonInfoRecorder extends JFrame implements ActionListener{
private JLabel nameLabel,sexLabel,ageLabel,tipLabel;//用来显示姓名、性别、年龄和提示栏
private JTextField nameTextField,ageTextField;//用来输入姓名和年龄
private JComboBox sex;//用来选择性别
private JTextArea info;//用来显示输入的个人信息
private JButton ok;//确定按钮
private JPanel northPanel,centerPanel,bigPanel;
public PersonInfoRecorder(){
super("个人信息录入器");
nameLabel = new JLabel("姓名");
sexLabel = new JLabel("性别");
ageLabel = new JLabel("年龄");
nameTextField = new JTextField(6);
ageTextField = new JTextField(6);
String sexs[] = {"男","女" };
sex = new JComboBox(sexs);
/*sex.addItemListener(
new ItemListener(){
public void itemStateChanged(ItemEvent event){
if(event.getStateChange() == ItemEvent.SELECTED){
String fsex = (String)sex.getSelectedItem();
info.setText(fsex);
}
}
});*/
ok = new JButton("确定");
ok.addActionListener(this);
northPanel = new JPanel();
northPanel.add(nameLabel);
northPanel.add(nameTextField);
northPanel.add(sexLabel);
northPanel.add(sex);
northPanel.add(ageLabel);
northPanel.add(ageTextField);
northPanel.add(ok);
info = new JTextArea("输入个人简要信息",5,30);
info.setLineWrap(true);
centerPanel = new JPanel();
JScrollPane scroll = new JScrollPane(info);
scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
centerPanel.add(scroll);
bigPanel = new JPanel();
bigPanel.add(northPanel);
bigPanel.add(centerPanel);
getContentPane().add(bigPanel);
setSize(400,200);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e){
if(nameTextField.getText().equals("")){
JOptionPane.showMessageDialog(null, "姓名不能为空!请输入姓名.");
}else{
String inform = info.getText();
if(inform.equals("输入个人简要信息")){
inform = "";
}
info.setText("姓名:" + nameTextField.getText()
+ "\n性别:" + (String)sex.getSelectedItem()
+ "\n年龄:" +
"\n简介:\n" + inform);
try{ //这里的异常处理语句是必需的.否则不能通过编译!
String sqlStr = "insert into Person values(nameTextField.getText(),"+
"(String)sex.getSelectedItem(),ageTextField.getText(),inform)";
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=Person";
//Person为数据库
String user="sa";
String password="";
Connection con = DriverManager.getConnection(url,user,password);
Statement st = con.createStatement();
st.executeUpdate( sqlStr );
st.close();
con.close();
} catch(ClassNotFoundException exception) {
exception.printStackTrace(System.out);
}
catch(Exception err) {
err.printStackTrace(System.out);
}
}
}
public static void main(String[] args) {
PersonInfoRecorder application = new PersonInfoRecorder();
}
}
编写一个简单的java程序显示个人信息:姓名,性别,出生年月,爱好?
public class MyInfo {
public static void main(String []args) {
System.out.println("你好,以下是我的个人信息:");
System.out.println("姓名:李刚");
System.out.println("性别:女");
System.out.println("出生年月:1998-08");
System.out.println("爱好:上网");}
}