zoukankan      html  css  js  c++  java
  • 第十六次作业

    package ydy57;
    import java.util.Random;
    
    public class test {
    
        public static void main(String args[]) {
            
             int a[] = new int[10];
                Random r = new Random();
                for (int i = 0; i < a.length; i++) {
                    a[i] = r.nextInt(100);
                }
                for (int i = 0; i < a.length; i++) {
                    System.out.println(a[i]);
                }
    
            }
    
        
    }
                
       

     2.通过电子版教材或者视频,自学Date类和SimpleDateFormat类,用以下格式输出
    系统当前时间
    公元2020年05月28日:今天是2020年的第149天,星期四

    package ydy57;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    public class test {
    
        public static void main(String args[]) {
            
              Date c = new Date();
                SimpleDateFormat a1 = new SimpleDateFormat("Eyyyy年MM月dd日");
                SimpleDateFormat a2 = new SimpleDateFormat("今天是Eyyyy年的第 D 天 ,E");
                System.out.println(a1.format(c));
                System.out.println(a2.format(c));
         
    
            }
    
        
    }
                
        
    
    
    
       

     3.输入一个邮箱地址,判断是否合法.如果合法,输出用户名.
    合法:必须包含@ 和 . 并且.在@的后面 (用indexof)
    用户名: 例如 dandan@163.com 用户名为dandan (用subString)

    package ydy57;
    import java.util.Scanner;
    public class test {
    
        public static void main(String args[]) {
            
               Scanner input = new Scanner(System.in);
                System.out.print("请输入合法的邮箱:");
                String s = input.nextLine();
                int a = 0;
                int b = 0;
                int x = 0;
                int y = 0;
                for (int i= 0; i < s.length() - 1; i++) {
                    String str = s.substring(i, i + 1);
                    if (str.equals("@")) {
                        a++;
                        x = i;
                    }
                    if (str.equals(".")) {
                       b++;
                        y = i;
                    }
                }
                if (a == 1 &&b == 1 && x < (y - 1) && x != 0 && y != s.length() - 1) {
                   s.endsWith("@qq.com");
                    System.out.println("合法");
                } else {
                    System.out.println("不合法");
                }
                String s1 = s.substring(0, s.indexOf("@"));
                System.out.println("用户名是:"+s1);
         
            }
        
    }                

  • 相关阅读:
    浅谈树状数组与线段树
    BZOJ1367:[Baltic2004]sequence
    浅谈左偏树
    BZOJ4003:[JLOI2015]城池攻占
    BZOJ2809:[APIO2012]dispatching
    BZOJ1455:罗马游戏
    模拟ssh远程执行命令
    基于TCP协议的socket套接字编程
    计算机网络基础知识
    元类( 控制对象产生和控制类产生)模板
  • 原文地址:https://www.cnblogs.com/ydy128/p/12979390.html
Copyright © 2011-2022 走看看