Java Object-oriented exercises 4

Source: Internet
Author: User

 PackageCom.lianxi; Public classStudent {//write Java applications. First, define the class--student that describe the student, including the study number (int),//attributes such as name (String), age (int), two methods: Student (int stuno,string name,int ages)//used to initialize the object, output () is used for outputting student information. Second, define a main class--//TestClass, create multiple objects of the student class in the main method of the Master class, using these objects to measure//try to student the function of the class.     intStuno,age;    String name; Student (intStuno,string name,intAge ) {         This. stuno=Stuno;  This. name=name;  This. age=Age ; }    voidOutPut () {System.out.println ("School Number:" +stuno+ "Name:" +name+ "Age:" +Age ); }     Public Static voidMain (string[] args) {Student S1=NewStudent (13254, "Zhang San", 21);                            S1.output (); }}

Write a Java application that consists of 2 classes: The Print class and the main class E. Print
There is a method in the class output () function that outputs 100 ~ 999 of all daffodils (the number of
The cubic and equals this three-digit number itself, such as: 371 = 33 + 73 + 13. ) in main class E, in the Main method
Test the class print.


Public
classPrint {voidoutput () {System.out.println ("The number of daffodils is"); for(intx=1;x<10&&x>=1;x++) { for(inty=0;y<10&&x>-1;y++) { for(intz=0;z<10&&x>-1;z++) { if(x*x*x+y*y*y+z*z*z==x*100+y*10+z) {System.out.println (x+ "" +y+ "" +z); } } } } } Public Static voidMain (string[] args) {//TODO Auto-generated method stubsPrint p1=NewPrint (); P1.output (); }}

Java Object-oriented exercises 4

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.