• java学习51天2020/8/25


    import java.util.Scanner;
    public class Circle {
         private double radius; //半径
         public Circle() {
         }
         public Circle(double radius) {
             this.radius = radius;
         }
         public void getArea() {
             double s;
             s=3.1415926*radius*radius;
             System.out.printf("面积:%-10f",s);
         }
         public static void main(String[] args) {
             Scanner in=new Scanner(System.in);
            double r;
             System.out.print("半径:");
             r=in.nextDouble();
             Circle c=new Circle(r);
             c.getArea();
         }
     }
    

     

     import java.util.Scanner;
    
     public class Tree {
        private int ages; //树龄
         public Tree() {
        }
        public Tree(int ages) {
        	this.ages=ages;
        }
         public void grow(int years) {
             ages+=years;
         }
         public void age() {
             System.out.println("树龄:"+ages);
         }
         public static void main(String[] args) {
             Scanner in=new Scanner(System.in);
             int a,b;
             System.out.print("请输入原有树龄:");
             a=in.nextInt();
             System.out.print("请输入生长的年数:");
             b=in.nextInt();
             Tree t=new Tree(a);
             t.grow(b);
             t.age();
         }
     }
    

     

    三.例题

  • 相关阅读:
    SpringBoot的缓存
    jsp标签指定id区域内容显示和隐藏
    Linux awk统计日志中出现过的IP(或出现次数最多的N个IP)
    回文数
    算法z形字符串
    最长回文字符串
    redis与Mysql数据同步
    算法(1)
    滑动窗口算法
    HTTP长连接和短连接
  • 原文地址:https://www.cnblogs.com/qiangini/p/13583412.html
Copyright © 2020-2023  润新知