你地址你自己找你在哪的你試試你電話這是你你不睡覺自己的隨便你
創(chuàng)新互聯(lián)專注于南雄企業(yè)網(wǎng)站建設,響應式網(wǎng)站開發(fā),成都做商城網(wǎng)站。南雄網(wǎng)站建設公司,為南雄等地區(qū)提供建站服務。全流程按需定制制作,專業(yè)設計,全程項目跟蹤,創(chuàng)新互聯(lián)專業(yè)和態(tài)度為您提供的服務
package?demo19;
class?Student?{
private?String?name;
private?int?age;
private?float?score;
public?String?getName()?{
return?name;
}
public?void?setName(String?name)?{
this.name?=?name;
}
public?int?getAge()?{
return?age;
}
public?void?setAge(int?age)?{
this.age?=?age;
}
public?float?getScore()?{
return?score;
}
public?void?setScore(float?score)?{
this.score?=?score;
}
public?void?say()?{
System.out.println(this.name?+?"的年齡是"?+?this.age?+?",成績是"?+?this.score);
}
}
public?class?HelloWorld?{
public?static?void?main(String[]?args)?{
Student?student?=?new?Student();
student.setName("小明");
student.setAge(15);
student.setScore(92.5f);
student.say();
}
}
public class student3 ectends student1
{
void print()
{
System.out.println("這是小明的同學“);//重寫了父類中的print方法
}
public static void main(String[] args)
{
student3 st=new student3();
student1 st1=new student1();
st.print();//首先調用的是student3類中重寫的print方法。
st1.print();//其次調用的是student1父類中的print方法。
}
}
class student1
{
void print()
{
System.out.println("這是小明的同學");
System.out.println("他很優(yōu)秀的");
}
}
根據(jù)以上程序的運行結果為:
這是小明的同學
這是小明的同學
他很優(yōu)秀的
如果將st.print();和st1.print();在程序中調換位置,則是樓主認為的輸出結果:
這是小明的同學
他很優(yōu)秀的
這是小明的同學
double weigh;
weight是double型的
point(int a,byte b) {
age = a;
weigh = (byte)b;
System.out.println(age);
System.out.println(weigh);
}
那樣根本不是強制轉換
強制類型轉換也稱作顯式類型轉換;
如果被轉換的值的數(shù)據(jù)類型大于其目標類型,將會丟失部分信息;
如:
int x = 65;
char ch = x;
這樣的語句將報錯,因為char類型小于int類型,編譯器無法將其自動轉換,只能進行強制轉換:
int x = 65;
char ch = (char)x;
不難看出,在有類型提升的情況下,編譯器將自動進行類型轉換,否則就要進行強制類型轉換;
類型提升應遵循如下規(guī)則:
兩種類型必須兼容,且目標類型大于源類型,例如:
byte、char和short類型都可以提升為int型。
對于表達式而言,其最終結果將會與表達式中最高的數(shù)據(jù)類型相同。
這段代碼weight=(byte)b
b本來就是byte型的
再轉也沒用啊
一個byte型的值賦給double型會自動轉成double型
//題目說的不明確,想單獨提取出來每一個名字?還是什么意思呢?
//我把切割,和查找都給你標出來了,你看看吧,也不知道是不是你想表達的意思!
public?class?切割?{
public?static?void?main(String[]?args)?{
System.out.println("\n\t\t---------切割-------\n");
init();
}
private?static?void?init()?{
String?name="小明,小黃,小李";
//切割!
String[]?arr=name.split(",");
//切割完成遍歷!
for?(int?i?=?0;?i??arr.length;?i++)?{
System.out.println(arr[i]);
}
//抽查出現(xiàn)位置,這里注意,會算上逗號的位置索引的!
System.out.println("小明:出現(xiàn)在字符串中索引位置是:"+name.indexOf("小明"));
System.out.println("小黃:出現(xiàn)在字符串中索引位置是:"+name.indexOf("小黃"));
System.out.println("小李:出現(xiàn)在字符串中索引位置是:"+name.indexOf("小李"));
}
}
package com.example;
/**
1.利用學號和姓名處理基本信息:
(1)輸出:姓名,校名,專業(yè),年級(學號中第10位為專業(yè)位,1表示語文,2表示數(shù)學,3表示英語)。
格式為:姓名:小明,A大學 數(shù)學 專業(yè) 2016級學生
(2)輸出Email地址
格式為:姓名:小明 Email地址是:111111111311@mail.com
2.以1為父類定義子類實現(xiàn)成績管理
利用語文、數(shù)學、英語成績計算并輸出
計算并輸出語文、數(shù)學、英語三門課的成績總分,最高分,最低分
輸出格式為:學號: 姓名: 總分: 最高分: 最低分:
3.在main方法中使用實際的數(shù)據(jù)調用以上的功能
(生成一個對象是自己的姓名和學號)
*/
public class StudentScore extends Student {
//英語分數(shù)
private float enScore;
//語文分數(shù)
private float laScore;
//數(shù)學分數(shù)
private float maScore;
/**
* @param args
*/
public static void main(String[] args) {
StudentScore stu = new StudentScore();
stu.setStudentName("小明");
stu.setSchoolName("A大學");
stu.setGradeName(2016);
stu.setStudentID("2016061601");
stu.setEmail("111111111311@mail.com");
stu.setEnScore(90);
stu.setLaScore(80);
stu.setMaScore(70);
System.out.println(stu.printInfo());
System.out.println(stu.printEmail());
System.out.println(stu.printScore());
}
public float getEnScore() {
return enScore;
}
public void setEnScore(float enScore) {
this.enScore = enScore;
}
public float getLaScore() {
return laScore;
}
public void setLaScore(float laScore) {
this.laScore = laScore;
}
public float getMaScore() {
return maScore;
}
public void setMaScore(float maScore) {
this.maScore = maScore;
}
//最高分
public float maxScore(){
float maxScore = enScore;
if (laScore maxScore) {
maxScore = laScore;
}
if (maScore maxScore) {
maxScore = maScore;
}
return maxScore;
}
//最低分
public float minScore(){
float minScore = enScore;
if (laScore minScore) {
minScore = laScore;
}
if (maScore minScore) {
minScore = maScore;
}
return minScore;
}
//總分
public float totalScore(){
float totalScore = 0;
totalScore = enScore + laScore + maScore;
return totalScore;
}
public String printScore(){
StringBuffer strBuff =new StringBuffer();
strBuff.append("學號 :");
strBuff.append(studentID);
strBuff.append("姓名 :");
strBuff.append(studentName);
strBuff.append(" 總分:");
strBuff.append(totalScore());
strBuff.append(" 最高分:");
strBuff.append(maxScore());
strBuff.append(" 最低分:");
strBuff.append(minScore());
return strBuff.toString();
}
}
class Student {
//姓名
public String studentName;
//學號
public String studentID;
//年級
public int gradeName;
//學校名稱
public String schoolName;
//電子郵箱
public String email;
public String getStudentName() {
return studentName;
}
public void setStudentName(String studentName) {
this.studentName = studentName;
}
public String getStudentID() {
return studentID;
}
public void setStudentID(String studentID) {
if(studentID.length()10){
throw new RuntimeException("學號長度不夠10位");
}
this.studentID = studentID;
}
public int getGradeName() {
return gradeName;
}
public void setGradeName(int gradeName) {
this.gradeName = gradeName;
}
public String getSchoolName() {
return schoolName;
}
public void setSchoolName(String schoolName) {
this.schoolName = schoolName;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
if(!email.contains("@")){
throw new RuntimeException("學號長度不夠10位");
}
this.email = email;
}
public String printInfo(){
StringBuffer strBuff =new StringBuffer();
strBuff.append("姓名 :");
strBuff.append(studentName);
strBuff.append(",");
strBuff.append(schoolName);
strBuff.append(" ");
char type = studentID.charAt(9);
if(type == '1'){
strBuff.append("語文");
}else if(type == '2'){
strBuff.append("數(shù)學");
}else if(type == '3'){
strBuff.append("英語 ");
}
strBuff.append("專業(yè) ");
strBuff.append(gradeName);
strBuff.append("級學生 ");
return strBuff.toString();
}
public String printEmail(){
StringBuffer strBuff =new StringBuffer();
strBuff.append("姓名 :");
strBuff.append(studentName);
strBuff.append(" ");
strBuff.append(" Email地址是:");
strBuff.append(email);
return strBuff.toString();
}
}
新聞名稱:小明的位置java代碼,Java代碼的位置怎么改
文章路徑:http://muchs.cn/article24/hcgjje.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供商城網(wǎng)站、網(wǎng)站改版、軟件開發(fā)、網(wǎng)站制作、、搜索引擎優(yōu)化
聲明:本網(wǎng)站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)