Skip to content

Commit 1f8fc05

Browse files
Add files via upload
1 parent ef24250 commit 1f8fc05

File tree

4 files changed

+119
-0
lines changed

4 files changed

+119
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
title: Number Conversions
3+
description: Converts from one numeric dat type to other
4+
author: SarvariHarshitha
5+
tags: Integer, Long, Double, Character
6+
---
7+
8+
```java
9+
public class NumericConversions {
10+
public static void main(String[] args) {
11+
12+
// int to long
13+
14+
int i = 200;
15+
long l = (long) i;
16+
System.out.println(l);
17+
18+
// long to int
19+
20+
long l1 = 12334567L;
21+
int i1 = (int) l1;
22+
System.out.println(i1);
23+
24+
// int to double
25+
26+
int i2 = 293;
27+
double d = (double) i2;
28+
System.out.println(d);
29+
30+
// double to int
31+
32+
double d2 = 1374.8;
33+
int i3 = (int) d2;
34+
System.out.println(i3);
35+
36+
// char to int
37+
38+
char c1 = 'c';
39+
char c2 = 'H';
40+
int i4 = (int) c1;
41+
int i5 = (int) c2;
42+
System.out.println(i4);
43+
System.out.println(i5);
44+
45+
// int to char
46+
int i6 = 69;
47+
char c3 = (char) i6;
48+
System.out.println(c3);
49+
}
50+
}
51+
```
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
title: String to Boolean
3+
description: Converts String type to Boolean type
4+
author: SarvariHarshitha
5+
tags: String, Boolean, type-conversion
6+
---
7+
8+
```java
9+
public class StringandBoolean {
10+
public static void main(String[] args) {
11+
12+
// String to Boolean
13+
String s1 = "Hi"; // prints false
14+
String s2 = "true";
15+
boolean b1 = Boolean.parseBoolean(s2);
16+
System.out.println(b1);
17+
18+
// Boolean to String
19+
20+
boolean b2 = true;
21+
String s3 = String.valueOf(b2);
22+
System.out.println(s3);
23+
System.out.println(Boolean.toString(b2));
24+
}
25+
}
26+
```
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
title: String to Character
3+
description: Converts String type to Character type
4+
author: SarvariHarshitha
5+
tags: String, Character, type-conversion
6+
---
7+
8+
```java
9+
public class StringandChar {
10+
public static void main(String[] args) {
11+
12+
String s = "quickSnip";
13+
char c = s.charAt(0); //Prints character at 1st index
14+
System.out.println(c);
15+
16+
}
17+
}
18+
```
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
title: String to Integer
3+
description: Converts String type to Integer type
4+
author: SarvariHarshitha
5+
tags: String, Integer, type-conversion
6+
---
7+
8+
```java
9+
public class StringandInt {
10+
public static void main(String[] args) {
11+
12+
// String to Int
13+
String s = "200";
14+
int i = Integer.parseInt(s);
15+
System.out.println(i);
16+
17+
// Int to String
18+
int a = 10;
19+
String s1 = String.valueOf(a);
20+
System.out.println(s1);
21+
22+
}
23+
}
24+
```

0 commit comments

Comments
 (0)