Strings are a sequence of characters. In the Java programming language, strings are objects.In string the objects are created two ways:
WAP to enter strings in java without using any function
class strings{
public static void main(String args[])
{
char ch[]={'s','i','n','g','h'}; //Entered words character by character
String s1="Maninder singh"; //Entered words in string
String s2=new String(s1); //String object created using new keyword
System.out.println(s2+"\n");
System.out.println(s1+"\n"); //String used using string literal
System.out.println(ch);
}
}
Output of the program:
- Using string literal.
- Using new keyword.
WAP to enter strings in java without using any function
class strings{
public static void main(String args[])
{
char ch[]={'s','i','n','g','h'}; //Entered words character by character
String s1="Maninder singh"; //Entered words in string
String s2=new String(s1); //String object created using new keyword
System.out.println(s2+"\n");
System.out.println(s1+"\n"); //String used using string literal
System.out.println(ch);
}
}
Output of the program:
No comments:
Post a Comment