-
-
Notifications
You must be signed in to change notification settings - Fork 129
New snippets in Java #150
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
Closed
Closed
New snippets in Java #150
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
Add files via upload
- Loading branch information
commit 1f8fc05ceba4fd194f9000032e82a8a7887d38e6
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
--- | ||
title: Number Conversions | ||
description: Converts from one numeric dat type to other | ||
author: SarvariHarshitha | ||
tags: Integer, Long, Double, Character | ||
--- | ||
|
||
```java | ||
public class NumericConversions { | ||
public static void main(String[] args) { | ||
|
||
// int to long | ||
|
||
int i = 200; | ||
long l = (long) i; | ||
System.out.println(l); | ||
|
||
// long to int | ||
|
||
long l1 = 12334567L; | ||
int i1 = (int) l1; | ||
System.out.println(i1); | ||
|
||
// int to double | ||
|
||
int i2 = 293; | ||
double d = (double) i2; | ||
System.out.println(d); | ||
|
||
// double to int | ||
|
||
double d2 = 1374.8; | ||
int i3 = (int) d2; | ||
System.out.println(i3); | ||
|
||
// char to int | ||
|
||
char c1 = 'c'; | ||
char c2 = 'H'; | ||
int i4 = (int) c1; | ||
int i5 = (int) c2; | ||
System.out.println(i4); | ||
System.out.println(i5); | ||
|
||
// int to char | ||
int i6 = 69; | ||
char c3 = (char) i6; | ||
System.out.println(c3); | ||
} | ||
} | ||
``` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
title: String to Boolean | ||
description: Converts String type to Boolean type | ||
author: SarvariHarshitha | ||
tags: String, Boolean, type-conversion | ||
--- | ||
|
||
```java | ||
public class StringandBoolean { | ||
public static void main(String[] args) { | ||
|
||
// String to Boolean | ||
String s1 = "Hi"; // prints false | ||
String s2 = "true"; | ||
boolean b1 = Boolean.parseBoolean(s2); | ||
System.out.println(b1); | ||
|
||
// Boolean to String | ||
|
||
boolean b2 = true; | ||
String s3 = String.valueOf(b2); | ||
System.out.println(s3); | ||
System.out.println(Boolean.toString(b2)); | ||
} | ||
} | ||
``` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- | ||
title: String to Character | ||
description: Converts String type to Character type | ||
author: SarvariHarshitha | ||
tags: String, Character, type-conversion | ||
--- | ||
|
||
```java | ||
public class StringandChar { | ||
public static void main(String[] args) { | ||
|
||
String s = "quickSnip"; | ||
char c = s.charAt(0); //Prints character at 1st index | ||
System.out.println(c); | ||
|
||
} | ||
} | ||
``` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
--- | ||
title: String to Integer | ||
description: Converts String type to Integer type | ||
author: SarvariHarshitha | ||
tags: String, Integer, type-conversion | ||
--- | ||
|
||
```java | ||
public class StringandInt { | ||
public static void main(String[] args) { | ||
|
||
// String to Int | ||
String s = "200"; | ||
int i = Integer.parseInt(s); | ||
System.out.println(i); | ||
|
||
// Int to String | ||
int a = 10; | ||
String s1 = String.valueOf(a); | ||
System.out.println(s1); | ||
|
||
} | ||
} | ||
``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.