Question

In: Computer Science

A) Declare a String variable called myString0 and initialize it to "Java". B) Declare a String...

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.

Solutions

Expert Solution

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
   }
}


Related Solutions

Declare a string variable and initialize it with your first name ( in C++)
Declare a string variable and initialize it with your first name ( in C++)
In Java form Declare and assign a char variable called myLetter to z. Write a Java...
In Java form Declare and assign a char variable called myLetter to z. Write a Java statement that makes myLetter uppercase. Write a java statement that finds out if myLetter is a digit. Write a java statement that finds out if myLetter is an upper case letter. Assume myLetter = ‘Z’; What is the output for System.out.print(myLetter++); Assume myLetter = ‘Z’; What is the output for System.out.print(++myLetter); Assume myLetter = ‘Z’; What is the output for System.out.print(myLetter--); What happens when...
Write a script that will first initialize a string variable that will store x and y...
Write a script that will first initialize a string variable that will store x and y coordinates of a point in the form ‘x 3.1 y 6.4’. Then, use string manipulating functions to extract the coordinates and plot them. ANS % create a string variable of the form 'x 3.1 y 6.4' % extract the x and y coordinates and plot str = 'x 2.3 y 4.5'; [letter rest] = strtok(str); [x rest] = strtok(rest); [letter rest] = strtok(rest); y...
A) Declare 'buffer as string.'a' and 'b' as integers.Set the value for 'a' is 100. B)...
A) Declare 'buffer as string.'a' and 'b' as integers.Set the value for 'a' is 100. B) Write a program to find the address location for buffer 'a' and 'b' and three segments in the process memory. thank you. pls answer with proper explaination
Declare and initialize an array to store the course name or code.
Declare and initialize an array to store the course name or code.
Write a java code segment to declare an array of size 10 of type String and...
Write a java code segment to declare an array of size 10 of type String and read data for them from a file, prompt user for the file name. Data is stored in a file with 1 string per line.
Write in Java: Write a method called: public static String[] noIdenticalCombine(String[] array1, String[] array2) { //...
Write in Java: Write a method called: public static String[] noIdenticalCombine(String[] array1, String[] array2) { // instructions: returns an array that contains all the Strings in array1 and array2 but without repetition. order does not matter, but it will return array1's elements and then array2's element that are not in array1. Assume there are no duplicates are in array1 and array2. Could use count which is how many str there are in array2, where !contains(array1, str). May an array of...
Part A: Write a set of statements that declare a variable of type double called yourNum,...
Part A: Write a set of statements that declare a variable of type double called yourNum, then prompts the user to input a value which gets stored into that variable. Part B: Write a set of statements that displays the phrase "Even Number!" when the value in the variable count is an even number but displays the phrase “That is odd” otherwise. Declare and initialize all variables. Part C: Write the necessary code to swap (exchange) the values in two...
Java - Write an abstract class called Shape with a string data field called colour. Write...
Java - Write an abstract class called Shape with a string data field called colour. Write a getter and setter for colour. Write a constructor that takes colour as the only argument. Write an abstract method called getArea()
Meant to be written in Java JDK 14.0 A String object is called palindrome if it...
Meant to be written in Java JDK 14.0 A String object is called palindrome if it is same when read from the front and the end. For example, String “abcba” is palindrome, while “12322” is not. Write Java program to check a String object of 5 characters is palindrome or not: (a) The comparison is case sensitive (b) The comparison is case insensitive
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT