Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please answer the following questions in the java language. 1. Create a method (function) with an int type parameter. This function will print out prime

Please answer the following questions in the java language.

1. Create a method (function) with an int type parameter. This function will print out prime numbers on screen range from 0 to the parameter value. The function will return the number of the prime numbers. Use main() method to test if your function works well.

2. Read and try to understand the following example:

image text in transcribed

Summarize the using of Scanner: how to read data from keyboard, how to read data from a file,

and how to read data from a web page.

3. Whats the output of the following program:

public class NewClass

{

public static void main(String[] args)

{

String s1 = "Computer Science";

int x = 262;

String s2 = s1 + " " + x;

String s3 = s2.substring(10,17);

String s4 = " is fun";

String s5 = s2 + s4;

System.out.println("s1: " + s1.replace("e", "E"));

System.out.println("s2: " + s2.toLowerCase());

System.out.println("s3: " + s3);

System.out.println("s4: " + s4.toUpperCase());

System.out.println("s5: " + s5);

//showing effect of precedence

x = s1.indexOf("e",9);

int y = s1.indexOf("e");

String s6 = x + y + "total";

String s7 = "total " + x + y;

String s8 = " " + x + y + "total";

System.out.println("s6: " + s6);

System.out.println("s7: " + s7);

System.out.println("s8: " + s8);

}

}

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_2

Step: 3

blur-text-image_3

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

Database Concepts International Edition

Authors: David M. Kroenke

6th Edition International Edition

0133098222, 978-0133098228

More Books

Students also viewed these Databases questions

Question

11 Recruitment strategies.

Answered: 1 week ago