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 static void main(String[] args) { | |
int[] arr= {1,2,3}; | |
for(int element : arr) | |
{ | |
System.out.println(element); | |
} | |
} |
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 static void main(String[] args) { | |
int b = (7 > 2) ? 1 : 0; | |
System.out.println(b); | |
} |
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 static void main(String[] args) { | |
loop1: for (int i = 0; i <5 ; i++) { | |
loop2: for (int j = 0; j <5 ; j++) { | |
System.out.println(i+" "+j); | |
if (i==j) | |
break loop1; | |
} | |
} |
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 static void main(String[] args) { | |
String input = "Java is awesome"; | |
String inputWithoutSpaces = input.replace(" ",""); | |
// System.out.println(inputWithoutSpaces); // String without spaces | |
int count = inputWithoutSpaces.length(); | |
System.out.println("Total characters without spaces : " + count); | |
} |
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 static void main(String[] args) { | |
String input = "Java is awesome"; | |
int count = (int) input.chars().filter(ch -> ch!=' ').count(); | |
System.out.println("Total characters without spaces : " + count); | |
} |
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 static void main(String[] args) { | |
String input ="Java is awesome"; | |
int counter=0; | |
for (int i = 0; i < input.length(); i++) { | |
// if character is not space, increase the counter | |
if (input.charAt(i)!=' ') |
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
print("hey,"end=" ") | |
print("there") |
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
print("hey \nthere") |
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
print("hey there") | |
print("hey there") |
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 static void main(String[] args) { | |
Character char1 = new Character('a'); | |
Character char2 = new Character('b'); | |
int char1Code = Character.hashCode(char1); | |
int char2Code = Character.hashCode(char2); | |
if (char1Code==char2Code) { | |
System.out.println("the characters are same"); |