e Secure httpscourseseasasuedulcse110dicurrenthwshw3html App
Solution
Part1:
1. Jovo Progromming JAVA PROGRAMMING
String n1,n2,n3;
n1=\"Java Programming\";
n2=n1.toUpperCase(); //JAVA PROGRAMMING
n3=n1 + \" \" + n2; // Java Programming JAVA PROGRAMMING
System.out.println(n3.replace(\'a\',\'o\')); // Jovo Progromming JAVA PROGRAMMING
2. num3=Math.sqrt(num1+num2);
3. lemon
apple
int num=57, max=35;
if(num>=max*2) //condition evaluates to false. So \'if\' block won\'t be entered.
System.out.println(\"orange\");
System.out.println(\"lemon\");
System.out.println(\"apple\");
Part 2:
Assignment3.java:
import java.util.Scanner;
public class Assignment3 {
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
System.out.println(\"Please enter a string\");
String string1=sc.nextLine();
//First string is read in string1 variable
System.out.println(\"Please enter another string\");
String string2=sc.nextLine();
//Second string is read in string2 variable
if(string1.length()%2==0)
//If number of characters in first String is divisible by 2, it\'s even
System.out.println(\"The first string\'s length is even\");
else
//If number of characters in first String is not divisible by 2, it\'s odd
System.out.println(\"The first string\'s length is odd\");
if(string2.length()%2==0)
//If number of characters in second String is divisible by 2, it\'s even
System.out.println(\"The second string\'s length is even\");
else
//If number of characters in second String is not divisible by 2, it\'s odd
System.out.println(\"The second string\'s length is odd\");
if(string1.equals(string2)) //It checks if 2 strings are equal
System.out.println(\"The two strings are same\");
else
System.out.println(\"The two strings are different\");
if(string1.compareTo(string2)>0) //if string1>string2, positive value is returned
System.out.println(\"The first string is lexically larger\");
else if(string1.compareTo(string2)<0) //if string1<string2, negative value is returned
System.out.println(\"The second string is lexically larger\");
else //if strings are equal, 0 is returned
System.out.println(\"The strings are lexically equal\");
//charAt function gives the first character of the String
System.out.println(\"The first character of the first string is \"+ string1.charAt(0));
System.out.println(\"The first character of the second string is \"+ string2.charAt(0));
// \'+\' concatenates value of 2 strings
System.out.println(\"The concatenation of the two strings is \"+ string1+string2);
// toUpperCase() function returns the String in Upper case.
System.out.println(\"The first string using uppercase letters: \"+ string1.toUpperCase());
System.out.println(\"The second string using uppercase letters: \"+ string2.toUpperCase());
}
}
Test Case 1:
Please enter a string
carrots
Please enter another string
Potatoes
The first string\'s length is odd
The second string\'s length is even
The two strings are different
The first string is lexically larger
The first character of the first string is c
The first character of the second string is P
The concatenation of the two strings is carrotsPotatoes
The first string using uppercase letters: CARROTS
The second string using uppercase letters: POTATOES
Test Case 2:
Please enter a string
cabbage
Please enter another string
cabbage
The first string\'s length is odd
The second string\'s length is odd
The two strings are same
The strings are lexically equal
The first character of the first string is c
The first character of the second string is c
The concatenation of the two strings is cabbagecabbage
The first string using uppercase letters: CABBAGE
The second string using uppercase letters: CABBAGE
Note: Please write the header information(assignment number, lab letter, name, etc) in comments.


