欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Java continue break制作简单聊天室程序

程序员文章站 2024-02-26 13:19:16
java continue break 制作简单聊天室程序,屏蔽不文明语言,显示每句话聊天时间 package com.swift; import java...

java continue break 制作简单聊天室程序,屏蔽不文明语言,显示每句话聊天时间

package com.swift;

import java.text.simpledateformat;
import java.util.date;
import java.util.scanner;

public class chatwithbreakcontinue {

  public static void main(string[] args) {
    scanner scan = new scanner(system.in);
    date date = null;
    // long timemillis=date.gettime();
    // long timemillis2=system.currenttimemillis();
    system.out.println("欢迎来到简单聊天程序");
    system.out.println("请输入你的名字");
    string name = scan.nextline();
    system.out.println("开始聊天了");
    system.out.println("说再见离开聊天");
    for (;;) {
      string msg = scan.nextline();
      date = new date();
      simpledateformat sdf = new simpledateformat("yyyy-mm-dd hh:mm:ss");
      string time = sdf.format(date);
      if (msg.equals("再见")) {
        break;
      } else if (msg.equals("*")) {
        system.out.println("注意文明用语");
        continue;
      } else if (msg.equalsignorecase("shazi")) {
        system.out.println("注意文明用语");
        continue;
      } else if (msg.equals("笨")) {
        system.out.println("注意文明用语");
        continue;
      }
      system.out.println("192.168.1.*" + name + "说: " + msg + " " + time);
    }
  }
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。