Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Program on Java #7

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/src/Break.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
*/
public class Break {
public static void main(String[] args) {
label1: for (int i = 0; i < 10; i++)
{
label1: for (int i = 0; i < 10; i++) {
if (i == 5) break label1;
System.out.println(i);
}
Expand Down
2 changes: 0 additions & 2 deletions src/src/Continue.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
public class Continue {
public static void main(String[] args) {
int i = 0;

label1:

while (i < 10) {
i++;
System.out.println("Hello");
Expand Down
1 change: 0 additions & 1 deletion src/src/DoWhile.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ public static void main(String[] args) {
int i = 0;
do {
System.out.println(i++);

}while (i < 10);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code formatting.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still needs code formatting.

}
}
3 changes: 1 addition & 2 deletions src/src/For.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
*/
public class For {
public static void main(String[] args) {
for (int i = 0; i < 10; i++)
{
for (int i = 0; i < 10; i++) {
System.out.println(i);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/src/ForEach.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
public class ForEach {
public static void main(String[] args) {
List<Integer> list = Arrays.asList(7, 10, 1, 5, 2);
list.forEach(item -> System.out.println(String.format("%s, %s, %s",item,list.indexOf(item),list.toString())));
list.forEach(item -> System.out.println(String.format("%s, %s, %s",item,list.indexOf(item),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code formatting.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't undestrand, how to formatting this code?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can have a look at Google Java Style Guide. Your IDE definitely provides tools to format code according to the selected code style. For example, if you use IntellijIdea, you can format your code using Alt + Cmd + L.

list.toString())));
System.out.println();
list.forEach(System.out::print);
System.out.println();
Expand Down
2 changes: 1 addition & 1 deletion src/src/Map.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ public class Map {
public static void main(String[] args) {

Function<Integer,Void> log = s -> {System.out.println(s); return null;};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code style.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a forEach(), you don't need this function at all.

Arrays.stream(new Integer[]{7, 10, 1, 5, 2}).map(x -> x * 2).map(log);
Arrays.stream(new Integer[]{7, 10, 1, 5, 2}).map(x -> x * 2).forEach(System.out::println);
}
}