-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathString in java-2
More file actions
69 lines (63 loc) · 2.76 KB
/
Copy pathString in java-2
File metadata and controls
69 lines (63 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
1]write a simple string program to take from a user.
import java.util.*;
class UserInputDemo1
{
public static void main(String[] args)
{
Scanner sc= new Scanner(System.in);
System.out.print("Enter a string: ");
String str= sc.nextLine();
System.out.print("You have entered: "+str);
}
}
======================================================================================================================================================================
2]how do you concatenate two strings in java?
concat()method
=====================================================================================================================================================================
3] how do you find the length of the string in java explain with an example.
Use inbuilt length() method
======================================================================================================================================================================
4]how do you compare two strings in java
Using == operator
======================================================================================================================================================================
5]write a program to find the length of the string” refrigerator”.
class main
{
public static void main(String[] args)
{
String s = “refrigerator”;
System.out.print("string lenght: "+s.length());
}
}
======================================================================================================================================================================
6] write a program to check if the letter ‘e’ is present in the word ‘Umbrella’.
class main
{
public static void main(String[] args)
{
String s = “Umbrella”;
if(word.contains(“e”))
{
System.out.print("It is present”);
}
else
{
System.out.print("It is not present”);
}
}
}
======================================================================================================================================================================
7]write a program to delete all consonants from the string “Hello, have a good day”.
public class Main {
public static void main(String[] args) {
String str = "Hello, have a good day";
String vowels = ('a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'));
StringBuilder sb = new StringBuilder();
for (int i = 0; i < str.length(); i++) {
if (vowels.contains(str.charAt(i))) {
sb.append(str.charAt(i));
}
}
System.out.println(sb.toString());
}
}