zoukankan      html  css  js  c++  java
  • 首先,定义一个Print类,它有一个方法void output(int x),如果x的值是1,在控制台打印出大写的英文字母表;如果x的值是2,在 控制台打印出小写的英文字母表。其次,再定义一个主类——TestClass,在主类 的main方法中创建Print类的对象,使用这个对象调用方法output ()来打印出大 小写英文字母表。

    package lianxi;
    
    public class Print_1 {
        int x;
    
        Print_1(int x) {
            this.x = x;
        }
    
        void outPut() {
            String a = "abcdefghijklmnopqrstuvwxyz";
            if (x == 1) {
                System.out.println(a.toUpperCase());
            } 
            else if (x == 2) {
                System.out.println(a);
            } 
            else {
                System.out.println("不可执行");
            }
        }
    
        public static void main(String[] args) {
    
            Print_1 Print1 = new Print_1(1);
            Print1.outPut();
    
            Print_1 Print2 = new Print_1(2);
            Print2.outPut();
    
            Print_1 Print3 = new Print_1(3);
            Print3.outPut();
    
        }
    }

  • 相关阅读:
    第十一章关联容器
    第十章泛型算法
    第九章
    第八章
    阅读记录
    java.lang.Class阅读笔记
    java.time包阅读笔记
    CLion运行多个main函数
    c++中lower_bound和upper_bound中的comp参数
    如何写dfs
  • 原文地址:https://www.cnblogs.com/wenwen123/p/5501645.html
Copyright © 2011-2022 走看看