资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

小明的位置java代码,Java代码的位置怎么改

ccf201812-2小明放学 java代码 想求大佬解惑我代码错哪

你地址你自己找你在哪的你试试你电话这是你你不睡觉自己的随便你

创新互联专注于南雄企业网站建设,响应式网站开发,成都做商城网站。南雄网站建设公司,为南雄等地区提供建站服务。全流程按需定制制作,专业设计,全程项目跟踪,创新互联专业和态度为您提供的服务

java 编程 修改下面的代码 要求显示小明的年龄是15,成绩是92.5

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();

}

}

请帮我看看这段JAVA程序,给我讲解一下

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("他很优秀的");

}

}

根据以上程序的运行结果为:

这是小明的同学

这是小明的同学

他很优秀的

如果将st.print();和st1.print();在程序中调换位置,则是楼主认为的输出结果:

这是小明的同学

他很优秀的

这是小明的同学

关于java 代码解答

double weigh;

weight是double型的

point(int a,byte b) {

age = a;

weigh = (byte)b;

System.out.println(age);

System.out.println(weigh);

}

那样根本不是强制转换

强制类型转换也称作显式类型转换;

如果被转换的值的数据类型大于其目标类型,将会丢失部分信息;

如:

int x = 65;

char ch = x;

这样的语句将报错,因为char类型小于int类型,编译器无法将其自动转换,只能进行强制转换:

int x = 65;

char ch = (char)x;

不难看出,在有类型提升的情况下,编译器将自动进行类型转换,否则就要进行强制类型转换;

类型提升应遵循如下规则:

两种类型必须兼容,且目标类型大于源类型,例如:

byte、char和short类型都可以提升为int型。

对于表达式而言,其最终结果将会与表达式中最高的数据类型相同。

这段代码weight=(byte)b

b本来就是byte型的

再转也没用啊

一个byte型的值赋给double型会自动转成double型

JAVA中一个字段比如 name='小明','小黄','小李';怎么分开查

//题目说的不明确,想单独提取出来每一个名字?还是什么意思呢?

//我把切割,和查找都给你标出来了,你看看吧,也不知道是不是你想表达的意思!

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]);

}

//抽查出现位置,这里注意,会算上逗号的位置索引的!

System.out.println("小明:出现在字符串中索引位置是:"+name.indexOf("小明"));

System.out.println("小黄:出现在字符串中索引位置是:"+name.indexOf("小黄"));

System.out.println("小李:出现在字符串中索引位置是:"+name.indexOf("小李"));

}

}

在线等,急!用JAVA编写程序,题目如下:

package com.example;

/**

1.利用学号和姓名处理基本信息:

(1)输出:姓名,校名,专业,年级(学号中第10位为专业位,1表示语文,2表示数学,3表示英语)。

格式为:姓名:小明,A大学 数学 专业 2016级学生

(2)输出Email地址

格式为:姓名:小明 Email地址是:111111111311@mail.com

2.以1为父类定义子类实现成绩管理

利用语文、数学、英语成绩计算并输出

计算并输出语文、数学、英语三门课的成绩总分,最高分,最低分

输出格式为:学号: 姓名: 总分: 最高分: 最低分:

3.在main方法中使用实际的数据调用以上的功能

(生成一个对象是自己的姓名和学号)

*/

public class StudentScore extends Student {

//英语分数

private float enScore;

//语文分数

private float laScore;

//数学分数

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("数学");

}else if(type == '3'){

strBuff.append("英语 ");

}

strBuff.append("专业 ");

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://cdkjz.cn/article/hcgjje.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220