找到 34423 篇文章 关于编程
2K+ 次浏览
在这里,我们将了解如何使用 gcc 从 C 或 C++ 代码生成汇编程序输出。gcc 提供了一个很棒的功能,可以在执行源代码时获取所有中间输出。要获取汇编程序输出,我们可以为 gcc 使用选项“-S”。此选项显示编译后的输出,但在发送到汇编程序之前。此命令的语法如下所示。gcc –S program.cpp现在,让我们看看输出将是什么样子。这里我们使用一个简单的程序。在这个程序中,两个数字存储在变量 x 和 y 中,然后 ... 阅读更多
485 次浏览
创建输入流并设置字符串:DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream("pqrs tu v wxy z".getBytes()));getBytes() 方法用于将字符串转换为字节序列并返回一个字节数组。现在返回一个输入字节:(char) inputStream.readByte()示例import java.io.ByteArrayInputStream; import java.io.DataInputStream; public class Demo { public static void main(String[] args) throws Exception { DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream("pqrs tu v wxy z".getBytes())); System.out.print((char) inputStream.readByte()); System.out.print((char) inputStream.readByte()); inputStream.close(); } }输出Pq
2K+ 次浏览
假设以下为我们的字符串数组,我们需要对其进行排序:String[] str = { "Tom", "Jack", "Harry", "Zen", "Tim", "David" };在 sort() 方法中,创建一个自定义比较器对上述字符串进行排序。在这里,两个字符串相互比较,并且过程继续:Arrays.sort(str, new Comparator < String > () { public int compare(String one, String two) { int val = two.length() - one.length(); if (val == 0) val = one.compareToIgnoreCase(two); return val; } });示例import java.util.Arrays; import java.util.Comparator; public class Demo ... 阅读更多
238 次浏览
创建两个时间点:Instant time1 = Instant.now(); Instant time2 = Instant.now().plusSeconds(50);使用 between() 获取两个时间点之间的时间差:long resMilli = Duration.between(time1, time2).toMillis();示例import java.time.Duration; import java.time.Instant; public class Demo { public static void main(String[] args) { Instant time1 = Instant.now(); Instant time2 = Instant.now().plusSeconds(50); long resMilli = Duration.between(time1, time2).toMillis(); System.out.println("两个时间间隔之间的时间差 = "+resMilli); } }输出两个时间间隔之间的时间差 = 50000
356 次浏览
首先,设置 Clock:Clock clock = Clock.systemUTC();现在,创建 LocalDateTime:LocalDateTime dateTime = LocalDateTime.now(clock);示例import java.time.Clock; import java.time.LocalDateTime; public class Demo { public static void main(String[] args) { Clock clock = Clock.systemUTC(); System.out.println("Clock = "+Clock.systemDefaultZone()); LocalDateTime dateTime = LocalDateTime.now(clock); System.out.println("LocalDateTime = "+dateTime); } }输出Clock = SystemClock[Asia/Calcutta] LocalDateTime = 2019-04-19T09:29:50.605820900
404 次浏览
首先,设置日期:LocalDateTime dateTime = LocalDateTime.of(2019, Month.SEPTEMBER, 6, 20, 10);现在,将日期时间格式化为 BASIC_ISO_DATE 格式:String str = dateTime.format(DateTimeFormatter.BASIC_ISO_DATE);示例import java.time.LocalDateTime; import java.time.Month; import java.time.format.DateTimeFormatter; public class Demo { public static void main(String[] args) { LocalDateTime dateTime = LocalDateTime.of(2019, Month.SEPTEMBER, 6, 20, 10); System.out.println("DateTime = "+dateTime); String str = dateTime.format(DateTimeFormatter.BASIC_ISO_DATE); System.out.println("格式化后的日期 = "+str); } }输出DateTime = 2019-09-06T20:10 格式化后的日期 = 20190906
659 次浏览
让我们首先创建一个字符串数组:String[] strArr = new String[] { "r", "p", "v", "y", "s", "q" };现在,使用 Arrays.sort() 方法按字母顺序对数组进行排序。在这里,我们已将顺序设置为不区分大小写:Arrays.sort(strArr, String.CASE_INSENSITIVE_ORDER);示例import java.util.Arrays; public class Demo { public static void main(String[] args) { String[] strArr = new String[] { "r", "p", "v", "y", "s", "q" }; System.out.println("按字母顺序排序数组..."); Arrays.sort(strArr, String.CASE_INSENSITIVE_ORDER); for (int a = 0; a < strArr.length; a++) { System.out.println(strArr[a]); ... 阅读更多
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP
