Java Small problem

Source: Internet
Author: User

1 , enter an integer through the keyboard N , Programming computing 1+2+3+...+n the value.

2 , enter any by keyboard 6 integer, the maximum number of outputs and the decimal.

3 , write program calculation 12-22+32-42+...+972-982+992-1002 the value.

4. Define a student class student, define 4 member variable id,age,last_name (last name), first_name (first name) in the class, and then define a method GetName return the full name of the person,in the main class, create an object of the student class, assign a value to the above field, and invoke the method to output the full name. 5. Define a class named Cylinder that represents a cylinder, define 2 member variable r in the class to represent the bottom radius, height for height, and set the base radius of the cylinder, the method of high value Initcylinder (), the method for calculating the bottom area getarea (), Method of calculating volume Getvolume (). create an object of the cylinder class in the main class, calling the Initcylinder () method at the same time, giving the radius and high assignment, calling Getarea () and Getvolume () to calculate the bottom area and volume of the cylinder. ? 6, define a class person, including two member variables name and ID (respectively, name and number), two methods sleep and eat. In the Sleep method output "sleep stream 56 saliva", in the Eat method respectively output "baby to eat milk." ? Test in the main class, output the name and number, and call the sleep method and the Eat method in it.
</pre><pre name= "code" class= "Java" >1, import Java.util.scanner;public class Test1 {public static void main ( String[] args) {Scanner sc=new Scanner (system.in); int n,i,sum=0;n=sc.nextint (); for (i=1;i<=n;i++) sum+=i;        SYSTEM.OUT.PRINTLN (sum);}}
2.
Import Java.util.arrays;import Java.util.scanner;public class Test2 {public static void main (string[] args) {Scanner sc=n EW Scanner (system.in); int a[]=new int[6];int i;for (i=0;i<6;i++) a[i]=sc.nextint (); Arrays.sort (a); System.out.println (A[0]); System.out.println (A[5]);}        }

3.
public class Test3 {public static void main (string[] args) {int i=12,j=22,n,sum=0;for (n=1;n<=98;n++) {sum+=i-j;i+=10; j+=10;}   SYSTEM.OUT.PRINTLN (sum);}}

4.
Class Student{int Id;int age; String last_name; String First_name;void initstudent (String l,string f) {last_name=l;first_name=f;} String get () {return first_name+last_name;}} public class Test4 {public static void main (string[] args) {student s=new student ();    S.initstudent ("Lin", "Yu");    System.out.println (S.get ());}}

5.
Class cylinder{double r;double height;void initcylinder (double l,double h) {r=l;height=h;} Double Getarea () {return math.pi*r*r;} Double Getvolume () {return math.pi*r*r*height;}} public class Test5 {public static void main (string[] args) {Cylinder c=new Cylinder (); C.initcylinder (8.6, 5.5); System.out.println (C.getarea ()); System.out.println (C.getvolume ());}}

6.
Class Person{int ID; String name; String sleep () {return "Sleep stream 56 saliva";} String Eat () {return "Baby Eats Milk";}} public class Test6 {public static void main (string[] args) {person p=new person (); System.out.println (P.eat ()); System.out.println (P.sleep ());}}



Java Small problem

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.