Java代码如下:
package Test01; import java.util.ArrayList; import java.util.List; public class Test02 { public static void main(String[] args){ a(); b(); c(); } @SuppressWarnings("unchecked") public static void a(){ @SuppressWarnings("rawtypes") List list = new ArrayList(); int sum = 0; for (int i = 0; i < 10; i++) { sum = sum+i; } System.out.println(sum); list.add(sum); System.out.println(list); } @SuppressWarnings("unchecked") public static void b(){ @SuppressWarnings("rawtypes") List list = new ArrayList(); for (int i = 0; i < 10; i++) { list.add(i); } System.out.println(list); } @SuppressWarnings("unchecked") public static void c(){ @SuppressWarnings("rawtypes") List list = new ArrayList(); for (int i = 10; i > 0; i--) { list.add(i); } System.out.println(list); } }
运行结果如下:
时间: 2024-10-23 12:17:45