This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class BlockScopeExample { | |
| public static void main(String args[]) { | |
| { | |
| int id = 10; | |
| id = id + 10; | |
| System.out.println("Inside block id is " + id); | |
| } | |
| System.out.println("Outside block id is " + id); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.Scanner; | |
| public class AgeCalculator { | |
| public static void main(String[] args) { | |
| System.out.print("Enter number of persons: "); | |
| Scanner scanner = new Scanner(System.in); | |
| int numberOfPersons = scanner.nextInt(); | |
| int maximumAge = Integer.MIN_VALUE; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.Scanner; | |
| public class NestedForLoopContinueBreakStatement { | |
| public static void main(String[] args) { | |
| for(int row = 1; row <= 9; row++) { | |
| if(row >= 6) { | |
| continue; | |
| } | |
| System.out.print("row " + row + ": "); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.Scanner; | |
| public class NestedForLoopBreakStatement { | |
| public static void main(String[] args) { | |
| for(int row = 1; row <= 9; row++) { | |
| System.out.print("row " + row + ": "); | |
| for(int column = 1; column <= 9; column++) { | |
| if(column >= 6) { | |
| break; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class NestedForLoop { | |
| public static void main(String[] args) { | |
| for(int row = 1; row <= 9; row++) { | |
| System.out.print("row " + row + ": "); | |
| for(int column = 1; column <= 9; column++) { | |
| System.out.print(column + " "); | |
| } | |
| System.out.println(); | |
| System.out.println(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class NestedForLoopV1 { | |
| public static void main(String[] args) { | |
| for(int row = 1; row <= 9; row++) { | |
| System.out.print("row " + row + ": "); | |
| System.out.println(); | |
| System.out.println(); | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.Scanner; | |
| public class GuessTheScoreBreakStatement { | |
| public static void main(String args[]) { | |
| int storedScore = 1234; | |
| int userScore = 0; | |
| Scanner scanner = new Scanner(System.in); | |
| do { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.Scanner; | |
| public class GuessTheScore { | |
| public static void main(String args[]) { | |
| int storedScore = 1234; | |
| int userScore = 0; | |
| Scanner scanner = new Scanner(System.in); | |
| do { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class ForStatement { | |
| public static void main(String args[]) { | |
| for (int counter = 1; counter <= 3; counter++) { | |
| System.out.println(counter); | |
| } | |
| System.out.println(); | |
| System.out.println("Good Bye!"); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class DoWhileStatement { | |
| public static void main(String args[]) { | |
| int counter = 1; | |
| do { | |
| System.out.println(counter); | |
| counter++; | |
| }while(counter <= 3); | |
| System.out.println(); |
NewerOlder