共 2 篇文章

标签:全民k歌用什么设备唱歌好听-全民k歌设备唱歌好听介绍

c语言怎么取整数-国外主机测评 - 国外VPS,国外服务器,国外云服务器,测评及优惠码

c语言怎么取整数

在C语言中,可以使用不同的方法来取整数,下面是一些常见的方法:,1、使用强制类型转换,通过将一个浮点数或双精度浮点数强制转换为整数类型(如int),可以取得该数的整数部分,这种方法适用于已知数值范围的情况。,输出结果为:,2、使用取模运算符(%),取模运算符(%)返回两个数相除后的余数,通过将一个浮点数或双精度浮点数与整数进行取模运算,可以得到该数的整数部分,需要注意的是,取模运算的结果是一个浮点数,如果希望得到整数结果,需要再次进行强制类型转换。,输出结果为:,3、使用floor函数和ceil函数,floor函数返回不大于给定参数的最大整数值,而ceil函数返回不小于给定参数的最小整数值,这两个函数可以在已知数值范围的情况下取得整数部分。,输出结果为:,输出结果为:,,#include <stdio.h> int main() { double num = 3.14; int integerPart = (int)num; printf(“Integer part: %d “, integerPart); return 0; },Integer part: 3,#include <stdio.h> int main() { double num = 7.89; int integerPart = (int)num % 5; // 先将num强制转换为整数,再与5取模 printf(“Integer part: %d “, integerPart); return 0; },Integer part: 2,#include <math.h> #include <stdio.h> int main() { double num = 3.14; int integerPart = (int)floor(num); // 使用floor函数取得不大于num的最大整数 printf(“Integer part using floor: %d “, integerPart); return 0; }

技术分享
java如何发送html邮件-国外主机测评 - 国外VPS,国外服务器,国外云服务器,测评及优惠码

java如何发送html邮件

要使用Java发送HTML邮件,可以使用JavaMail API,以下是详细步骤:,1、添加JavaMail依赖,在项目的pom.xml文件中添加JavaMail的依赖:,2、编写Java代码,创建一个Java类,如 HtmlEmailSender.java,并编写以下代码:,注意替换 your_email@example.com、 your_password和 recipient_email@example.com为实际的发件人邮箱、密码和收件人邮箱。,3、运行Java程序,运行 HtmlEmailSender.java,如果一切正常,收件人将收到一封包含HTML内容的邮件。,,<dependency> <groupId>com.sun.mail</groupId> <artifactId>javax.mail</artifactId> <version>1.6.2</version> </dependency>,import java.util.Properties; import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.AddressException; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; public class HtmlEmailSender { public static void main(String[] args) { // 设置邮件服务器属性 Properties properties = new Properties(); properties.put(“mail.smtp.host”, “smtp.example.com”); properties.put(“mail.smtp.port”, “587”); properties.put(“mail.smtp.auth”, “true”); properties.put(“mail.smtp.starttls.enable”, “true”); // 创建邮件会话 Session session = Session.getInstance(properties, new javax.mail.Authenticator() { protected javax.mail.PasswordAuthentication getPasswordAuthentication() { return new javax.mail.PasswordAuthentication(“your_email@example.com”, “your_password”); } }); try { // 创建邮件消息 MimeMessage message = new MimeMessage(session); message.setFrom(new InternetAddress(“your_email@example.com”)); message.addRecipient(Message.RecipientType.TO, new InternetAddress(“recipient_email@example.com”)); message.setSubject(“HTML邮件示例”); // 设置邮件内容为HTML格式 message.setContent(“<h1>欢迎使用Java发送HTML邮件!</h1><table border=’1′><tr><th>姓名</th><th>年龄</th></tr><tr><td>张三</td><td>30</td></tr></table>”, “text/html;charset=UTF8”); // 发送邮件 Transport.send(message); System.out.println(“邮件已成功发送!”); } catch (AddressException e) { e.printStackTrace(); } catch (MessagingException e) { e.printStackTrace(); } } },

技术分享