In: Computer Science
A) Declare a String variable called myString0 and initialize it to "Java".
B) Declare a String variable called myString1 and initialize it to "Programming".
C) Declare a String variable called myString2 and initialize it to "Language".
D) Print the concatenation of myString0 + " is a " + myString1 + " " + myString2 + ".".
E) Print the sum of the lengths of myString1 and myString2 (must call the length() method).
F) Print the 2nd, 4th, and 7th character of myString1 (must use the charAt() method), separated by commas.
G) Print the index of 'a' in myString0 (must use the indexOf() method).
H) Print myString2 converted to uppercase (must use the toUpperCase() method).
I) Print the 3rd through 8th character of myString1 (must use the substring() method).
J) Declare a String called myString3 and set it to "Whatever!", you must use the 'new' operator.
K) Declare a String called myString4 and set it to "Whatever!", you must use the 'new' operator.
L) Print a comparison of the two strings using (myString3 == myString4).
M) Print a comparison of the two strings using (myString3.equals(myString4)).
N) Declare three char variables c0, c1, and c2 with the values '^', 'G', and '7'.
O) Print the characters, separated by semicolons.
P) Print the ASCII value of the characters, separated by
commas.
HINT: Use a typecast of the character from char to
int.
import java.lang.*;
import java.util.*;
public class Main
{
public static void main(String[] args) {
String myString0="Java";//A declares myString0
String myString1="Programming";//B declares
myString1
String myString2="Language"; //C declares
myString2
String result1=myString0+" is a "+myString1+"
"+myString2+".";//D concatanation
System.out.println(result1);//printing
System.out.println("Sum of lengths of String1 and
String2"+myString1.length()+myString2.length());//e sum of
lengths
System.out.println(myString1.charAt(1)+","+myString1.charAt(3)+","+myString1.charAt(6));//F
charAt position printing
System.out.println("Index of a in String1 is
"+myString1.indexOf('a'));//G getting indexOf a
System.out.println("UppeCase of myString2 is
"+myString2.toUpperCase());//H converting into UpperCase
System.out.println("Substring in string1 is
"+myString1.substring(2,8));//I finding substring
String myString3=new String("Whatever!");//J declares
String3 using new
String myString4=new String("Whatever!");//K declares
String4 using new
System.out.println("Comparision of String3 and String4
using == "+(myString3==myString4));//L both are not refering to
same object so false
System.out.println("Comparision of String3 and String4
using equals "+myString3.equals(myString4));//M both string values
are equal so true
char c0='^',c1='G',c2='7';//N declares
Characters
System.out.println(c0+":"+c1+":"+c2);//O printing
chars
System.out.println("ascii values of chars are
"+(int)c0+","+(int)c1+","+(int)c2);//printing ascii values
}
}