zoukankan      html  css  js  c++  java
  • 类和对象基础题2

    编写Java应用程序。首先,定义描述学生的类——Student,包括学号(int)、

    姓名(String)、年龄(int)等属性;二个方法:Student(int stuNo,String name,int age)

    用于对对象的初始化,outPut()用于输出学生信息。其次,再定义一个主类——

    TestClass,在主类的main方法中创建多个Student类的对象,使用这些对象来测

    Student类的功能。

        int stuNo;
        String name;
        int age;
        Student(int stuNo,String name,int age)
        {
            this.stuNo=stuNo;
            this.name=name;
            this.age=age;
        }
        void outPut()
        {
            System.out.println("学号:"+stuNo+" "+"姓名:"+name+" "+"年龄:"+age);
        }
    public class TestClass {
    
        public static void main(String[] args) {
            Student stu1=new Student(12,"张三",18);
            stu1.outPut();
            Student stu2=new Student(23,"李四",15);
            stu2.outPut();
            Student stu3=new Student(78,"王五",19);
            stu3.outPut();
            Student stu4=new Student(42,"赵六",17);
            stu4.outPut();
    
        }
    
    }

    编写一个Java应用程序,该应用程序包括2个类:Print类和主类EPrint

    类里有一个方法output()功能是输出100 ~ 999之间的所有水仙花数(各位数字的

    立方和等于这个三位数本身,如: 371 = 33 + 73 + 13。)在主类Emain方法中来

    测试类Print

    public class Print {
    
        
        void output()
        {
            for (int num=100;num<1000;num++)
            {
                int gw=num%10;
                int sw=num/10%10;
                int bw=num/100%10;
                if (gw*gw*gw+sw*sw*sw+bw*bw*bw==num)
                {
                    System.out.println(num);
                }
            }
        }
        
    
    }
    public class E {
    
        public static void main(String[] args) {
            Print sum=new Print();
            
            sum.output();
    
        }
    
    }

  • 相关阅读:
    C++基础知识(二)
    C++基础知识(一)
    RT-thread 设备驱动组件之IIC总线设备
    RT-thread 设备驱动组件之SPI设备
    RT thread 设备驱动组件之USART设备
    RT-thread 设备驱动组件之PIN设备
    RT-thread finsh组件工作流程
    C语言知识点
    RT-thread main函数分析
    堆和栈的区别
  • 原文地址:https://www.cnblogs.com/wallan/p/5501718.html
Copyright © 2011-2022 走看看