Several simple basic programming questions

Source: Internet
Author: User
Tags print format

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.