189 8069 5689

java中输入性别的代码 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编程 通过文本行输入学生姓名,通过单选按钮选择性别,复选框选择课程,在文本框中显示所填写及选择信

package helloworld;

import java.awt.*;

import javax.swing.*;

//import com.borland.jbcl.layout.XYLayout;

//import com.borland.jbcl.layout.*;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

public class Frame1 extends JFrame {

//XYLayout xYLayout1 = new XYLayout();

JLabel jLabel1 = new JLabel();

JRadioButton jRadioButton1 = new JRadioButton();

JRadioButton jRadioButton2 = new JRadioButton();

JButton jButton1 = new JButton();

JLabel jLabel2 = new JLabel();

JCheckBox jCheckBox1 = new JCheckBox();

JCheckBox jCheckBox2 = new JCheckBox();

JCheckBox jCheckBox3 = new JCheckBox();

public static void main(String[] args) {

Frame1 frame=new Frame1();

frame.setBounds(100, 100, 200, 300);

frame.setVisible(true);

}

public Frame1() {

try {

jbInit();

} catch (Exception exception) {

exception.printStackTrace();

}

}

private void jbInit() throws Exception {

//getContentPane().setLayout(xYLayout1);

getContentPane().setLayout(new BoxLayout(getContentPane(),BoxLayout.Y_AXIS));

jLabel1.setText("性掘明 别:"虚散滑);

//xYLayout1.setWidth(326);

//xYLayout1.setHeight(214);

jButton1.setText("提 交");

jButton1.addActionListener(new Frame1_jButton1_actionAdapter(this));

jRadioButton2.setText("女差腊");

jLabel2.setText("爱 好:");

jCheckBox1.setText("唱歌");

jCheckBox2.setText("跳舞");

jCheckBox3.setText("阅读");

this.getContentPane().add(jLabel1);//, new XYConstraints(31, 60, 46, 21));

this.getContentPane().add(jRadioButton1);//,new XYConstraints(127, 60, -1, -1));

this.getContentPane().add(jRadioButton2);//,new XYConstraints(216, 60, -1, -1));

this.getContentPane().add(jLabel2);//, new XYConstraints(31, 111, -1, -1));

this.getContentPane().add(jCheckBox1);//, new XYConstraints(97, 106, -1, -1));

this.getContentPane().add(jCheckBox2);//,new XYConstraints(164, 106, -1, -1));

this.getContentPane().add(jCheckBox3);//,new XYConstraints(233, 106, -1, -1));

this.getContentPane().add(jButton1);//, new XYConstraints(124, 154, -1, -1));

jRadioButton1.setText("男");

jRadioButton1.setSelected(true);

ButtonGroup bg=new ButtonGroup();

bg.add(jRadioButton1);

bg.add(jRadioButton2);

}

public void jButton1_actionPerformed(ActionEvent e) {

System.out.println("性别:"+(jRadioButton1.isSelected()?jRadioButton1.getText():jRadioButton2.getText()));

if(jCheckBox1.isSelected()){

System.out.println(jCheckBox1.getText());

}

if(jCheckBox2.isSelected()){

System.out.println(jCheckBox2.getText());

}

if(jCheckBox3.isSelected()){

System.out.println(jCheckBox3.getText());

}

}

}

class Frame1_jButton1_actionAdapter implements ActionListener {

private Frame1 adaptee;

Frame1_jButton1_actionAdapter(Frame1 adaptee) {

this.adaptee = adaptee;

}

public void actionPerformed(ActionEvent e) {

adaptee.jButton1_actionPerformed(e);

}

}


当前文章:java中输入性别的代码 java输入姓名代码
文章链接:http://cdxtjz.cn/article/dsphdpj.html

其他资讯