真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

請(qǐng)輸入性別的Java代碼 運(yùn)行查詢時(shí)提示請(qǐng)輸入性別

java如何通過鍵盤輸入性別代號(hào)

//用Scanner讀入字符串,加個(gè)判斷就可以了

成都創(chuàng)新互聯(lián)主營(yíng)尚志網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營(yíng)網(wǎng)站建設(shè)方案,重慶APP開發(fā)公司,尚志h5微信小程序搭建,尚志網(wǎng)站營(yíng)銷推廣歡迎尚志等地區(qū)企業(yè)咨詢

public?static?void?main(String[]?args)?{

Scanner?s=new?Scanner(System.in);

String?sex=s.next();

if(sex.toLowerCase().equals("m"))

System.out.println("男性");

else?if(sex.toLowerCase().equals("n"))

System.out.println("女性");

else

System.out.println("未知");

}

java程序設(shè)計(jì),用scanner編寫,輸入姓名,性別,年齡,住址,婚否,可以輸出相應(yīng)的數(shù)據(jù)?

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

//再寫?地點(diǎn)。。。

System.out.println(name+"?你好,今年"?+?age+"歲");??//?Output?user?input

}}

用JAVA編寫一個(gè)程序,要求如下:

實(shí)現(xiàn)代碼如下:

Student類:

public class Student {

private String name;

private String sex;

private int age;

private double chinese;

private double math;

private double english;

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public String getSex() {

return sex;

}

public void setSex(String sex) {

this.sex = sex;

}

public int getAge() {

return age;

}

public void setAge(int age) {

this.age = age;

}

public double getChinese() {

return chinese;

}

public void setChinese(double chinese) {

this.chinese = chinese;

}

public double getMath() {

return math;

}

public void setMath(double math) {

this.math = math;

}

public double getEnglish() {

return english;

}

public void setEnglish(double english) {

this.english = english;

}

}

-----------------------------------------------------------------

StudentTest類:(測(cè)試類)

import java.util.Scanner;

public class StudentTest {

public static void main(String[] args) {

Student student = new Student();

Scanner sc = new Scanner(System.in);

System.out.println("請(qǐng)輸入姓名:");

student.setName(sc.next());

System.out.println("請(qǐng)輸入性別:");

student.setSex(sc.next());

System.out.println("請(qǐng)輸入年齡:");

student.setAge(sc.nextInt());

System.out.println("請(qǐng)輸入語文成績(jī)、數(shù)學(xué)成績(jī)、英語成績(jī):");

student.setChinese(sc.nextDouble());

student.setMath(sc.nextDouble());

student.setEnglish(sc.nextDouble());

Double count = student.getChinese()+ student.getMath()+student.getEnglish();

System.out.println("姓名:"+student.getName()+" 性別:"+student.getSex()+" 年齡:"+student.getAge());

System.out.println("總分:"+count+" 平均分:"+count/3);

}

}

運(yùn)行結(jié)果為:


分享題目:請(qǐng)輸入性別的Java代碼 運(yùn)行查詢時(shí)提示請(qǐng)輸入性別
瀏覽路徑:http://weahome.cn/article/ddcpsdp.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部