DEV Community

Khushi Thakuri
Khushi Thakuri

Posted on

Basic codes in java.

print

public class hk{
public static void main(String[] agrs){
System.out.println("hello people");
}
}

String

length.
public class bm{
public static void main(String[] agrs){
String name = "khushi thakuri";
System.out.println(name.length());
}
}
result= 14

Replace

public class fk{
public static void main(String[] agrs){
String name = "khannal";
String name2 = name.replace('k','t');
System.out.println(name2);
result=thannal

Substring
public class hk{
public static void main(String[] agrs) {
String name = "khusi and khanaa";
System.out.println(name.substring(0,5));
}
}
result=khusi

Concatenate
public class main{
public static void main(String[] agrs){
String name1 = "baba";
String name2 = "mama";
String name3 = name1 +"and" + name2;
System.out.println(name3);
}
}
result= baba and mama

charAt
public class ss{
public static void main(String[] agrs){
String name = "khusi";
System.out.println(name.charAt(1));
}
}
result = h

Top comments (0)