Java, write a loop from 1 to 150 and print a value on each line, plus foo on a multiple line of 3, print biz on multiples of 5, print Baz on multiples of 7.

Source: Internet
Author: User

Requirements: Write a loop from 1 to 150 and print a value in each row, and then print Foo on multiples of each of the 3 lines, print biz on multiples of 5, and print Baz on multiples of 7.

Packagestudy01; Public classFor { Public Static voidMain (string[] args) { for(inti = 1;i<=150;i++) {System.out.print (i); if(i%3==0) {System.out.print ("Foo"); } if(i%5==0) {System.out.print ("Biz"); } if(i%7==0) {System.out.print ("Baz"); } System.out.println (""); } }}

The output results are as follows:

1
2
3 foo
4
5 Biz
6 foo
7 Baz
8
9 foo
Ten Biz
11
Foo
13
Baz
Foo Biz
16
17
Foo
19
Biz
Foo Baz
22
23
Foo
-Biz
26
Foo
Baz
29
Foo Biz
31
32
Foo
34
Biz Baz
Foo
37
38
$ foo
+ Biz
41
Baz Foo
43
44
Foo Biz
46
47
-Foo
Baz
The Biz
Wuyi Foo
52
53
Wu Foo
About Biz
Baz
$ foo
58
59
Foo Biz
61
62
Baz Foo
64
The Biz
$ foo
67
68
Foo
Baz Biz
71
Foo
73
74
+ Foo Biz
76
Baz
+ Foo
79
Biz
Bayi Foo
82
83
Baz Foo
+ Biz
86
Foo
88
89
All Foo Biz
Baz
92
---Foo
94
The Biz
$ foo
97
98 Baz
The Foo
-Biz
101
102 Foo
103
104
Baz Foo Biz
106
107
108 Foo
109
The Biz
111 Foo
Baz
113
Foo
+ Biz
116
117 Foo
118
119 Baz
+ Foo Biz
121
122
123 Foo
124
All Biz
126 Foo Baz
127
128
129 foo
The Biz
131
Foo
133 Baz
134
135 Foo Biz
136
137
138 foo
139
Baz Biz
141 Foo
142
143
144 Foo
145 Biz
146
147 Foo Baz
148
149
Foo Biz

Java, write a loop from 1 to 150 and print a value on each line, plus foo on a multiple line of 3, print biz on multiples of 5, print Baz on multiples of 7.

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.