Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

09/16/2019 Task 1-Type casting Write a program that read three integers (use nextInt() method) and prints their average. Make sure the fractional part of the

image text in transcribed
image text in transcribed
09/16/2019 Task 1-Type casting Write a program that read three integers (use nextInt() method) and prints their average. Make sure the fractional part of the result is not lost. For example, if the three integers are 5, 6, and 8, the average should be 6.333. Hinta: Do not forget to import the package for Scanner class. Hint2: Type casting is needed. Task 2-Play with Strings Copy the following program to your Lab4 project. Format your entire program by correcting the indentions. (Ctrl+A then Ctrl+1) // *** // Stringplay.java // 1/ Play with String objects public class StringPlay public static void main (String[] args) String college = new String ("Pace University"); 1/ part (a), fill in your code here characters."); int stringLength; String changel, change2, change3, change4; 1/ part (b), fill in your code here System.out.println (college + " contains " + stringLength + 1/ part (c), fill in your code here 1/ part (d), fill in your code here 1/ part (e), fill in your code here 1/ part (f), fill in your code here 11 part (9), fill in your code here 17 1111 in your code here to print out each changed string. // part (e), fill in your code here // part (f), fill in your code here // part (g), fill in your code here // fill in your code here to print out each changed string. Complete the program by following the instructions below: (a) declare the variable town as String type and initialize it to "Princeton, NJ, USA". CS 121: Computer Programming I (b) Invokes the length method of the string class to find the length of the college String object and assigns the result to the stringLength variable. Now run your program and check if the print out information is correct. (c) complete the assignment statement so that changel is the substring of college with the 3 characters "Pac". Use subString method. Print changel out. (d) complete the assignment statement so that change is the substring of college with the characters "University". Use subString method. Print change2 out. (e) complete the assignment statement so that change 3 contains the same characters as college but all in upper case. Print change3 out. (f) complete the assignment statement so that changed is the same as change3 except all capital E's are replaced with the asterisk (*) character. (g) complete the assignment statement so that changes is the concatenation of variable college and variable town (besides the concat method, what else can you use?)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions