Java Novice Note 5

Source: Internet
Author: User

1. Binary conversion

/* Bonuses awarded by enterprises are subject to profit. Profit (I) less than or equal to $100,000, the bonus can be raised by 10%, the profit is higher than $100,000, less than $200,000, the portion of less than 100,000 yuan by 10% commission, higher than the portion of 100,000 yuan, a commission of 7.5%, 200,000 to 400,000, higher than 200,000 yuan, can commission 5% ; Between 400,000 and 600,000 is higher than the portion of 400,000 yuan, can commission 3%, 600,000 to 1 million, higher than 600,000 yuan portion, can commission 1.5%, higher than 1 million yuan, the portion of more than 1 million yuan by 1% Commission, from the keyboard input month profit I, the total bonus should be issued? */import Java.util.scanner;public class Demo1 {public static void main (String args[]) {/*system.out.println ("binary: 4" +int Eger.tobinarystring (4)); System.out.println ("Octal: +" +integer.tooctalstring (16)); System.out.println ("Hex: Ten" + integer.tohexstring); int a = 12328;int b,c,d,e,f;//take digit b = a% 10;//c = a% 100/10;c = a/10% 10;d = a/100% 10;e = a/1000% 10;f = a/10000; System.out.println ("b =" + B + "\TC =" + c); System.out.println ("D =" + D + "\te =" + E + "\TF =" + f); int a = 462,b,c,d,e,f;if (a <) {System.out.pri Ntln ("1-digit ...");   else if (a <) {B = a% 10;           c = a/10% 10; System.out.println ("2 digits ..." + B + c);}   else if (a < +) {b = a% 10;   c = a/10% 10;           d = a/100% 10; System.out.println ("3 digits ..." + B + C + D);}   else if (a < 10000) {B = a% 10;   c = a/10% 10;   d = a/100% 10;           E = a/1000% 10; SYSTEM.OUT.PRINTLN ("4 digits ..." + B + C + D + e);}   else {b = a% 10;   c = a/10% 10;   d = a/100% 10;   E = a/1000% 10;           f = a/10000; SYSTEM.OUT.PRINTLN ("5 digits ..." + B + C + D + e + f);} Scanner scan = new Scanner (system.in); System.out.println ("Please enter your information name, age, Score:"); String name = Scan.next ();//Gets the string int age = Scan.nextint ();//Gets the integer number double score = scan.nextdouble (); SYSTEM.OUT.PRINTLN ("Input information is as follows:"); System.out.println ("Name:" + name + "Age:" + ages + "score:" + score); Scanner scan = new Scanner (system.in);        System.out.println ("Please enter profit:");d ouble I = scan.nextdouble ();  Double bound = 0;//Bonus scheme if (i <=) {bound = i * 0.1;} else if (I <) {bound = ten * 0.1 + (I-10) * 0.075;//35 0.075} else if (I <) {bound = ten * 0.1 + * 0.075 + (I-20) * 0.05;} else if (I <) {bound = 10 * 0.1 + 10 * 0.075 + 20 * 0.05 + (I-40) * 0.03; } else if (I <) {bound = ten * 0.1 + * 0.075 + * 0.05 + * 0.03 + (I-60) * 0.015;} else {bound = 10 * 0. 1 + * 0.075 + * 0.05 + * 0.03 + + * 0.015 + (I-100) * 0.01; }system.out.println ("Bonus:" + bound);//string s = null;*/int a = 1, B = 6, c = 9;if (A > B) {if (a > C) {if (b > C) {Sys Tem.out.println ("@:" + A + B + c);} else {System.out.println (":" + A + C + b);}} else {System.out.println (":" + C + A + B);}} else {if (b > C) {if (a > C) {System.out.println (":" + B + A + c);} else {System.out.println (" : "+ B + C + a);}} else {System.out.println ("* *:" + C + B + a);}} int year = 2012;boolean isleapyear = year% 400 = = 0 | | Year% 4 = = 0 && Year% 100! = 0;}}

2. Encapsulation class

Declares that the class  class encapsulates public class Student {    String name;char sex;private int age;//property private int sno;    Provides access to properties by means of  methods to prevent illegal data from being stored in the attribute void Setage () {age = 30;if (aged > | | | Ages < 0) {           System.out.println ("illegitimate ...") ;   Age = 0;}         } int Getage () {        return age;//Returns the Age property value}void study () {SYSTEM.OUT.PRINTLN ("Learn! ...");} method void Speak () {System.out.println ("Hello everyone! ...");}}

3. Test class

Declare class public class Studenttest {public static void main (string[] args) {Student o = new Student ();//Create custom Object//o Student Object   Stud ENT class         int a = 20; System.out.println ("o.name =" + O.name); O.speak ();//Method call O.study (); o.name = "Zhang San"; o.sex = ' male ';//o.age = -20;o.setage (); O. Sno = 180;o.name = "Zhang Fei"; System.out.println ("o.name =" + O.name); System.out.println ("o.sex =" + O.sex);//system.out.println ("o.age =" + o.age); System.out.println ("o.getage () =" + O.getage ()); System.out.println ("O.sno =" + O.sno);}}

4. Test Class 1

Declare class public class StudentTest1 {public static void main (string[] args) {Student s = null;//declares the object's reference//s.study ();  New S = new Student ();//new Create Object Instantiation Object S.name = "John Doe"; System.out.println ("s.name =" + S.name); S.study (); Student s2 = new Student (); s2.name = "Zhang San"; System.out.println ("s2.name =" + S2.name); System.out.println ("s.name =" + S.name); S2.study ();}}

5. Class description

Declare class public class OBJ {    ///state  attribute instance variable string Name;char sex;int age;//behavior method  action void Speak () {System.out.println ( "Hello, everyone!" ...");}} Class Objtest {public static void main (string[] args) {obj o = new OBJ ();//Create custom object// Random ran = new random (); System.out.println ("o.name =" + O.name); O.speak (); o.name = "Zhang San"; o.sex = ' male '; o.age = 20;o.name = "Zhang Fei"; System.out.println ("o.name =" + O.name); System.out.println ("o.sex =" + O.sex); System.out.println ("o.age =" + O.age);}}

6. Class methods

Declare class public class MethodTest1 {    int a = 10;//associated with object    //method  no parameter no return value void Method1 () {System.out.println ("call Method1 () ");}    Return value type Add  method name () passed in parameter void add (int a, int b) {        int sum  = a + b;        System.out.println ("sum =" +  sum);}    parameter list data type variable name double calusal (int job,int house,int bound) {//system.out.println ("sum =" +  job + house + bound); 
   return Job + house + bound;//  return calculation result}public static void main (string[] args) {   MethodTest1 mt = new Method Test1 ();       int b = MT.A;   System.out.println ("b =" + b);   Mt.method1 ();   Mt.add (10, 6);//Called when the number of parameter types matches the declared method   Double salary = mt.calusal (8000,5000,6000);   System.out.println ("salary =" + salary);   The result returned also requires processing   double result = salary * 0.05; SYSTEM.OUT.PRINTLN ("result =" + result);}}

Java Novice Note 5

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.