package Chegg;
public class StringOperations {
public static void main(String[] args) {
// TODO Auto-generated method
stub
//creating new string oblect
String s1 = new String("Hello
there");
String s2 = new String("How are
you?");
//to find the length of string and
display it
System.out.println("Length is
"+s1.length());
//concatanation operator is +
System.out.println("concatanation
"+s1+s2);
//string array
String arr[] =
{"hello","there","How","are","you"};
System.out.println("String
Array");
for(int i=0;i<arr.length;i++)
{
System.out.println(arr[i]);
}
//uppercase
System.out.println("Uppercase
"+s1.toUpperCase());
//lowercase
System.out.println("Lowercase
"+s2.toLowerCase());
//replace
System.out.println("Replace
"+s2.replace('o', 'A'));
//compare
System.out.println("Compare
"+s2.compareTo(s1));
//substring
System.out.println("Substring
"+s1.substring(4));
//substring between
System.out.println("Substring
between "+s2.substring(2, 10));
//index of
System.out.println("indexof
"+s1.indexOf('t'));
//index of
System.out.println("indexof
"+s2.indexOf('u', 10));
//char at
System.out.println("charAt
"+s1.charAt(4));
}
}
Write Java Programs to perform the following: 1. To create a new String object 2. To...
JAVA PROGRAMMING I want to make sure I have learned the compareto statements correct and other things. This was on my lecture slide today and I don't understand the compare to regarding how they get values for the strings. Please answer the following. Suppose that s1, s2, and s3 are three strings, given as follows String s1 = "Welcome to Java". String s2 = "Programming is fun". String s3- "Welcome to Java" hat are the results of the following expressions?...
Java beginners: Show how to invoke the method grunf so that it will return the String HOPE. public static String grunf(String s1, String s2, String s3) { String s = s1.substring(1,2); if (s1.length()>s2.length() && s2.compareTo(s3)<0 && s3.indexOf(s)>0) return s1.substring(0,1) + s2.substring(1); else return s1.substring(0,1) + s2.substring(0,1) + s1.substring(0,1); }
Lab 6 Given the String String str = “Zhrx.aghkio.Gko123”; (a) Write Java code using the String class methods indexOf and substring to extract the three string surrounded by the periods. In other words String s1 will contain Zhrx, String s2 will contain aghkio and String s3 will contain Gko123. (b) Write a method of the form public static String minStr(String str1, String str2) which returns the string which is “smaller” based on the decimal values of the characters in...
Write a Java program for all items in Question Use System.out.println() for each resulting string. Let s1 be " Welcome " and s2 be " welcome ". Write the code for the following statements: a. Check whether s1 is equal to s2 and assign the result to a Boolean variable isEqual. b. Check whether s1 is equal to s2, ignoring case, and assign the result to a Boolean variable isEqual. c. Compare s1 with s2 and assign the result to...
Java Homework Problems: 4. • Examine AddImport.java. – Perform the following: – Replace the fully qualified name to access the Jlabel component with an import statement. – To import classes from the util package, replace multiple import statements with a single import statement. /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ import java.util.Calendar; import java.util.Date; public...
Topics: About Java What is a compiler, and what does it do? Characteristics of the languageStrongly typed and statically typed Everything has a data type & data types must be declared Case sensitive Object oriented System.out.print() vs. System.out.println() How to use the Scanner class to obtain user input Data typesWhat are they? Know the basic types like: int, double, boolean, String, etc. Variables What is a variable? Declarations Initialization Assignment Constants Reserved words like: What is a reserved word? Examples:...
language is java Restrictions: You are not allowed to use anything from the String, StringBuilder, or Wrapper classes. In general, you may not use anything from any other Java classes, unless otherwise specified. You are not allowed to use String literals in your code ("this is a string literal"). You are not allowed to use String objects in your code. The methods must be implemented by manipulating the data field array, The CSString Class: NOTE: Pay very careful attention to...
A java program for this question please! Recursion: A word is considered elfish if it contains the letters: e, l, and f in it, in any order. For example, we would say that the following words are elfish: whiteleaf, tasteful, unfriendly, and waffles, because they each contain those letters. Write a recursive method called elfish(), that, given a word, tells us whether or not that word is elfish. The signature of the method should be: public static boolean elfish(String word)...
Write a program in java to read a string object consisting 300 characters or more using index input Stream reader. The program should perform following operations. The String must have proper words and all kind of characters.(Use String class methods). a, Determine the length of the string count the number of letters in the strings , count the number of numeric object d. Calculate the number of special character e. Compute the ratio of the numeric to the total f....
Problem 1 1. In the src → edu.neiu.p2 → problem1 directory, create a Java class called HW4P1 and add the following: • The main method. Leave the main method empty for now. • Create a method named xyzPeriod that takes a String as a parameter and returns a boolean. • Return true if the String parameter contains the sequential characters xyz, and false otherwise. However, a period is never allowed to immediately precede (i.e. come before) the sequential characters xyz....