-
-
Notifications
You must be signed in to change notification settings - Fork 120
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module type="JAVA_MODULE" version="4"> | ||
<component name="NewModuleRootManager" inherit-compiler-output="true"> | ||
<exclude-output /> | ||
<content url="file://$MODULE_DIR$"> | ||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> | ||
</content> | ||
<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" /> | ||
<orderEntry type="sourceFolder" forTests="false" /> | ||
</component> | ||
</module> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* Created by PC on 07.06.2017. | ||
*/ | ||
public class Break { | ||
public static void main(String[] args) { | ||
label1: for (int i = 0; i < 10; i++) { | ||
if (i == 5) break label1; | ||
System.out.println(i); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* Created by PC on 07.06.2017. | ||
*/ | ||
public class Continue { | ||
public static void main(String[] args) { | ||
int i = 0; | ||
label1: | ||
while (i < 10) { | ||
i++; | ||
System.out.println("Hello"); | ||
if (i == 5) continue label1; | ||
System.out.println("World"); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* Created by PC on 07.06.2017. | ||
*/ | ||
public class DoWhile { | ||
public static void main(String[] args) { | ||
int i = 0; | ||
do {System.out.println(i++);}while (i < 10); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** | ||
* Created by PC on 07.06.2017. | ||
*/ | ||
public class For { | ||
public static void main(String[] args) { | ||
for (int i = 0; i < 10; i++) { | ||
System.out.println(i); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
/** | ||
* Created by PC on 07.06.2017. | ||
*/ | ||
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), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Code formatting. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't undestrand, how to formatting this code? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
list.forEach(x -> System.out.print(x)); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* Created by PC on 07.06.2017. | ||
*/ | ||
public class ForOf { | ||
public static void main(String[] args) { | ||
for (int elem: new int[]{7, 10, 1, 5, 2}) | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Code style. |
||
System.out.println(elem); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import java.util.Arrays; | ||
import java.util.function.Function; | ||
|
||
/** | ||
* Created by PC on 07.06.2017. | ||
*/ | ||
public class Map { | ||
public static void main(String[] args) { | ||
Arrays.stream(new Integer[]{7, 10, 1, 5, 2}).map(x -> x * 2).forEach(System.out::println); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* Created by PC on 07.06.2017. | ||
*/ | ||
public class While { | ||
public static void main(String[] args) { | ||
int i = 0; | ||
while (i<10) | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Code style. |
||
System.out.println(i); | ||
i++; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.