包含45.0java的词条

博主:adminadmin 2022-11-22 20:57:09 61

今天给各位分享45.0java的知识,其中也会对进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

java写类

文件一 学生封装文件Student.java

package student;

public class Student {

private String stuId;

private String stuName;

private double stuMark;

public Student() {

}

public Student(String stuId,String stuName,double stuMark){

this.stuId=stuId;

this.stuName=stuName;

this.stuMark=stuMark;

}

public void setStuId(String stuId) {

this.stuId = stuId;

}

public void setStuName(String stuName) {

this.stuName = stuName;

}

public void setStuMark(double stuMark) {

this.stuMark = stuMark;

}

public String getStuId() {

return stuId;

}

public String getStuName() {

return stuName;

}

public double getStuMark() {

return stuMark;

}

}

文件二 sutInfo.java,将10个学生信息放入LinkedList列表中

package student;

import java.util.LinkedList;

public class sutInfo {

private static LinkedList lis=new LinkedList();

public sutInfo() {

}

//在列表中放入10个学生实例,并返回

public static LinkedList getLinkeList(){

for(int i=0;i10;i++){

lis.add(new Student(i+"","name"+i,90+i));

}

return lis;

}

}

文件三prinStudent.java输出学生信息类,主方法类

package student;

import java.util.LinkedList;

public class prinStudent {

public prinStudent() {

}

public static void main(String[] arges){

String id=arges[0];

for(int i=0;i10;i++){

//从列表中重取出封装的学生对象

Student s=(Student)sutInfo.getLinkeList().get(i);

if(id.equals(s.getStuId())){//判断学生Id

//输出学生信息

System.out.println(s.getStuId());

System.out.println(s.getStuName());

System.out.println(s.getStuMark());

return;

}

}

}

}

三个文件放入同一个文件夹,然后分别编译,编译成功后执行prinStudent.class

命令为:java prinStudent

Java习题解答

11.B //应该为float f = 45.0f;

12.B

13.A

14.B

15.B

16.C //这里之说InputStream类,没有说哪个包下的,问的问题有点瑕疵,不过看其他问题,应该是初学,只考虑io下的。flush是OutputStream类方法。

17.B

18.D

19.C

20.C

float f=45.0是否正确

不正确。

float f=45.0是非法的,因为在java中浮点数的输入默认是double型,float型的大小没有double型大,所以需要强制类型转换才是正确的。

java运行错做.不知道怎么的

出错信息是数组越界了,出错的原因是你在本应该用j做循环子的循环的过程中,用i来控制循环条件了。

for(int j=0;itemperature[i].length;j++){

temperature[i][j]=(float)(45.0*Math.random()-10.0);

}

应该是

for(int j=0;jtemperature[i].length;j++){

temperature[i][j]=(float)(45.0*Math.random()-10.0);

}

public class WeatherFan {

public static void main(String[] args) {

float[][] temperature = new float[10][365];

for (int i = 0; i temperature.length; i++) {

for (int j = 0; j temperature[i].length; j++) {

temperature[i][j] = (float) (45.0 * Math.random() - 10.0);

}

}

for (int i = 0; i temperature.length; i++) {

float average = 0.0f;

for (int j = 0; j temperature[i].length; j++) {

average += temperature[i][j];

}

System.out.println("Average temperature at location" + (i + 1) + "=" + average

/ (float) temperature[i].length);

}

}

}

用JAVA编写五个学生三科成绩的平均值。谢谢啦

public class Student {

    private String name;

    private double chinese;

    private double math;

    private double english;

    public Student() {

    }

    public Student(String name, double chinese, double math, double english) {

        this.name = name;

        this.chinese = chinese;

        this.math = math;

        this.english = english;

    }

    public String getName() {

        return name;

    }

    public void setName(String name) {

        this.name = name;

    }

    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;

    }

}

public static double average(double... scores) {

    double total = 0.00;

    for (double score : scores) {

        total += score;

    }

    double average = total / scores.length;

    return BigDecimal.valueOf(average).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue();

}

public static void main(String[] args) {

    Student[] students = {

            new Student("张三", 85.0, 91.5, 88.0),

            new Student("李四", 55.0, 98.0, 72.5),

            new Student("王五", 99.0, 92.0, 96.0),

            new Student("赵七", 45.0, 58.0, 55.0),

            new Student("孙八", 77.5, 72.0, 78.0)

    };

    for (Student student : students) {

        System.out.println(student.getName() + "的平均分为:"

                + average(student.getChinese(), student.getMath(), student.getEnglish()));

    }

}

java题目 下面哪个是非法的 float f=11.1 float f=45.0 char c=

float f = 11.1 和 float f = 45.0都是非法的

在java中如果你输入一个小数。那么java编译器默认认为他是一个double,

那么这个式子就相当于 float a = double b; 很显然是不行的,在末尾加一个f表示你输入的是float类型就可以了。

关于45.0java和的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

The End

发布于:2022-11-22,除非注明,否则均为首码项目网原创文章,转载请注明出处。