Print the integer from 1 to 100, but the number that contains 7 must be skipped,
Each row outputs seven numbers that meet the conditions, separated by spaces. The print format is as follows:
1 2 3 4 5 6 8
Print the number of data that meets the condition
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++; } } }}
Print the multiplication table
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. Define the arraylist set and save it to the following strings: "ABC", "123", "Java", "MySQL", and "Don't run"
2. traverse the set, fill the left side of the element with a length less than 4 with a string of 0, and print out all the elements in the modified set on the console.
Output result format: [0abc, 0123, Java, MySQL, 0 don't run]
Package review; import Java. util. arraylist; import Java. util. arrays;/* idea * defines the arraylist set ---> arraylist <string> xxx = new arraylist <> (); * stores the set ---> XXX. add (data); * traverse the set ---> XXX. fori ---> XXX. get (I) **/public class demo {public static void main (string [] ARGs) {arraylist <string> List = new arraylist <> (); list. add ("ABC"); list. add ("123"); list. add ("Java"); list. add ("MySQL"); list. add ("Don't run"); 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) + ",");}}}}
Method 2
Package review; import Java. util. arraylist; import Java. util. arrays; public class demo {public static void main (string [] ARGs) {arraylist <string> List = new arraylist <> (); list. add ("ABC"); list. add ("123"); list. add ("Java"); list. add ("MySQL"); list. add ("Don't run"); arraylist <string> 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 );}}
Several simple basic programming questions