用E语言写一个登录程序代码
时间: 2023-02-28 15:01:05 浏览: 63
以下是用 E 语言写的登录程序的示例代码:
```
import std/io;
fn main() {
var username = "";
var password = "";
std.io.println("请输入用户名:");
username = std.io.readln();
std.io.println("请输入密码:");
password = std.io.readln();
if (username == "admin" && password == "1234") {
std.io.println("登录成功!");
} else {
std.io.println("登录失败!");
}
}
```
这是一个简单的登录程序,它接收用户输入的用户名和密码,然后使用 if 语句判断用户名和密码是否匹配,并进行相应的操作。请注意,上面的代码只是一个示例,在实际应用中可能需要使用加密算法来保护密码,并从数据库中获取用户名和密码,而不是固定地存储在代码中。
相关问题
写一个socket简易聊天程序代码,用java语言
以下是一个简单的 Java Socket 聊天程序的示例代码:
Server.java
```java
import java.io.*;
import java.net.*;
public class Server {
public static void main(String[] args) {
try {
ServerSocket serverSocket = new ServerSocket(8000);
System.out.println("Server started");
Socket socket = serverSocket.accept();
System.out.println("Client connected");
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
while (true) {
String message = in.readLine();
if (message == null) {
break;
}
System.out.println("Client: " + message);
out.println("Server: " + message);
}
socket.close();
System.out.println("Client disconnected");
} catch (IOException e) {
e.printStackTrace();
}
}
}
```
Client.java
```java
import java.io.*;
import java.net.*;
public class Client {
public static void main(String[] args) {
try {
Socket socket = new Socket("localhost", 8000);
System.out.println("Connected to server");
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
BufferedReader console = new BufferedReader(new InputStreamReader(System.in));
while (true) {
String message = console.readLine();
if (message == null) {
break;
}
out.println(message);
System.out.println("Server: " + in.readLine());
}
socket.close();
System.out.println("Disconnected from server");
} catch (IOException e) {
e.printStackTrace();
}
}
}
```
这个聊天程序使用了 Java 的 Socket API,Server 程序监听端口 8000,等待客户端连接;Client 程序向服务器的 8000 端口发起连接请求。一旦连接建立,就可以在控制台输入消息并发送给对方。程序会一直运行直到某方断开连接。
用一个Java语言写一个高级表白代码
好的,以下是一个简单的Java表白程序:
```java
import java.util.Scanner;
public class Confession {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入你心仪的人的名字:");
String name = scanner.nextLine();
System.out.println("请输入你想说的话:");
String message = scanner.nextLine();
System.out.println("正在向" + name + "表白...");
for (int i = 0; i < message.length(); i++) {
System.out.print(message.charAt(i));
try {
Thread.sleep(100); // 控制输出速度
} catch (InterruptedException e) {
e.printStackTrace();
}
}
System.out.println("\n" + name + ",我喜欢你!");
}
}
```
使用方法:
1. 在命令行中输入 `javac Confession.java` 编译程序;
2. 在命令行中输入 `java Confession` 运行程序;
3. 按照程序提示输入你心仪的人的名字和想说的话;
4. 程序会逐字输出你想说的话,并在最后表白。
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)