1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
telo118 [61]
3 years ago
6

1. Print out the string length of s1 2. Loop through characters in s2 with charAt() and display reversed string 3. Compare s2, s

3 with compareTo(), print out which string (s2 or s3) is greater than which string (s2 or s3), or equal, print the result out 4. Use the regionMatches to compare s2 and s3 with case sensitivity of the first 8 characters and print out the result (match or not) . 5. Find the location of the first character 'g' in s1, print it out 6. Find the last location of the substring "class" from s2, print it out
Computers and Technology
1 answer:
konstantin123 [22]3 years ago
7 0

Answer:

See explaination

Explanation:

public class StringLab9 {

public static void main(String args[]) {

char charArray[] = { 'C', 'O', 'S', 'C', ' ', '3', '3', '1', '7', ' ', 'O', 'O', ' ', 'C', 'l', 'a', 's', 's' };

String s1 = new String("Objected oriented programming language!");

String s2 = "COSC 3317 OO class class";

String s3 = new String(charArray);

// To do 1: print out the string length of s1

System.out.println(s1.length());

// To do 2: loop through characters in s2 with charAt and display reversed

// string

for (int i = s2.length() - 1; i >= 0; --i)

System.out.print(s2.charAt(i));

System.out.println();

// To do 3: compare s2, s3 with compareTo(), print out which string (s2 or s3)

// is

// greater than which string (s2 or s3), or equal, print the result out

if (s2.compareTo(s3) == 0)

System.out.println("They are equal");

else if (s2.compareTo(s3) > 0)

System.out.println("s2 is greater");

else

System.out.println("s3 is greater");

// To do 4: Use the regionMatches to compare s2 and s3 with case sensitivity of

// the first 8 characters.

// and print out the result (match or not) .

if (s2.substring(0, 8).compareTo(s3.substring(0, 8)) == 0)

System.out.println("They matched");

else

System.out.println("They DONT match");

// To do 5: Find the location of the first character 'g' in s1, print it out

int i;

for (i = 0; i < s2.length(); ++i)

if(s2.charAt(i)=='g')

break;

System.out.println("'g' is present at index " + i);

// To do 6: Find the last location of the substring "class" from s2, print it

// out

int index = 0, ans = 0;

String test = s2;

while (index != -1) {

ans = ans + index;

index = test.indexOf("class");

test = test.substring(index + 1, test.length());

}

System.out.println("Last location of class in s2 is: " + (ans + 1));

// To do 7: Extract a substring from index 4 up to, but not including 8 from

// s3, print it out

System.out.println(s3.substring(4, 8));

} // end main

} // end class StringLab9

You might be interested in
What is output if the user enters -5?
7nadin3 [17]

Answer:

The left

Explanation:

6 0
2 years ago
Read 2 more answers
What does cro stand for?
mr_godi [17]
It stands for Chief Risk Officer 
8 0
2 years ago
Read 2 more answers
What is the purpose of the GETPIVOTDATA function?
Mrac [35]

Answer:to export the PivotTable data into another worksheet

Explanation:hope this helps :D

7 0
2 years ago
Read 2 more answers
Write the definition of a method printDottedLine, which has no parameters and doesn't return anything. The method prints to stan
Bond [772]

Answer:

public static void printDottedLine()

{

  System.out.println(".....");

}

Explanation:

The above written code is in JAVA and it is the method definition of the method mentioned in the question.Since the method returns nothing hence it's return type is void and it does not have any arguments hence there is nothing written in the parenthesis.In JAVA System.out.println is used for standard output and trminates them by newline.

3 0
3 years ago
Which two graphs best represent the motion of an object falling freely?
larisa [96]
The graph would have to be pointing completely down to be falling freely.
4 0
3 years ago
Other questions:
  • How to remove a channel from favorite list on suddenlink?
    15·1 answer
  • Given four values representing counts of quarters, dimes, nickels and pennies, output the total amount as dollars and cents. Out
    10·1 answer
  • In 1-2 paragraphs discuss the three main purposes of design and provide examples for each. Also explain how a design might serve
    15·1 answer
  • What command would you run from a windows command line to test a computer's network stack?
    7·1 answer
  • Random Walker Collisions In lecture, we saw how to model the behavior of a random walker on a 2D grid using a Monte Carlo simula
    8·1 answer
  • What stores all software and files on your computer and reads and writes data onto a spinning magnetic or optical disk?
    6·1 answer
  • Help help help help help!!!
    7·1 answer
  • What can be used to help diagnose and fix network connection problems?
    8·1 answer
  • Assignment 6: Animation
    7·1 answer
  • Write an algorithm of telephone call system​
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!