打印1到100之内的整数,但数字中包含7的要跳过,
每行输出7个满足条件的数,之间用空格分隔,打印格式如下:1 2 3 4 5 6 8
打印满足条件的数据的个数
public class Demo { public static void main(String[] args) { int count = 1; for (int i = 1; i <= 100; i++) { if(i/7==10||i%10==7){ continue; }else if(count%7==0){ System.out.println(i); count++; }else{ System.out.print(i+" "); count++; } } }}
打印乘法口诀表
public class Demo { public static void main(String[] args) { for (int i = 1; i <= 9; i++) { for (int j = 1; j <=i; j++) { System.out.print(i+"*"+j+"="+(i*j)+" "); } System.out.println(); } }}
1.定义ArrayList集合,存入如下字符串:“abc”,“123”,“java”,“mysql”,“别跑啊”
2.遍历集合,将长度小于4的元素左边填充字符串0,并在控制台打印输出修改后集合中所有元素输出结果格式: [0abc,0123,java,mysql,0别跑啊]package Review;import java.util.ArrayList;import java.util.Arrays;/*思路* 定义ArrayList集合--->ArrayListxxx = new ArrayList<>();* 存入集合--->xxx.add(数据);* 遍历集合 ---> xxx.fori--->xxx.get(i)* */public class Demo { public static void main(String[] args) { ArrayList list = new ArrayList<>(); list.add("abc"); list.add("123"); list.add("java"); list.add("mysql"); list.add("别跑啊"); System.out.print("["); for (int i = 0; i < list.size(); i++) { if(i==list.size()-1){ System.out.print("0"+list.get(i)+"]"); }else if(list.get(i).length()<4){ System.out.print("0"+list.get(i)+","); }else { System.out.print(list.get(i)+","); } } }}
第二种方法
package Review;import java.util.ArrayList;import java.util.Arrays;public class Demo { public static void main(String[] args) { ArrayListlist = new ArrayList<>(); list.add("abc"); list.add("123"); list.add("java"); list.add("mysql"); list.add("别跑啊");ArrayList list1 = new ArrayList<>(); for (int i = 0; i < list.size(); i++) { if(list.get(i).length()<4){ list1.add( "0"+list.get(i)); }else{ list1.add(list.get(i)); } } System.out.println(list1); }}