KnightOfEmpire
Mr & Ms Pac-Man
- 12/6/06
- 206
- 26
mình mới học về java nên nên ko rành lắm, mà nó cho bài tập làm chẳng hiểu gì cả >.<, ai giúp mình dc ko, đây là đề. Cảm ơn mọi người trước 

1) Write and test a Java application with just a main method class called TimeConverter to do
the following:
(i) Prompt for and read in an integer value representing a time in seconds.
(ii) Print out the equivalent time in hours, minutes and seconds, in the format hrs:mins:secs. If
either mins or secs is less than 10, a leading zero should be displayed.
[Hint: in Java, 276 / 60 gives 4 and 276 % 60 gives 36, so 276 seconds is 00:04:36 in the
required format.]
2) Let testString be the name of a String variable. Then
testString.length()
gives the number of characters in the corresponding character string.
For example, suppose the string corresponding to testString is "Java Programming" and
the following code is executed:
int len = testString.length();
System.out.println("The length of the test String is: " + len);
then the following output is obtained:
The length of the test String is: 16
Now suppose that we want to know what character is at a given position in the string corresponding
to testString. In Java, we count positions in a character string starting at position 0. For
example, the character at position 0 in "Java Programming” is 'J'. To get the value of the
character at a specified position (index) in testString we write the following:
testString.charAt(index)
For example, if as before the string corresponding to testString is "Java Programming",
and the following code is executed:
int index = 3;
char ch = testString.charAt(index);
System.out.println("The character at position " + index
+ " in the test String is: " + ch);
then the following output is obtained:
The character at position 3 in the test String is: a
Create a Java application with a main method class called CharCount. Make sure that you enable
the Create Main Class check box so that NetBeans generates an empty main method class. Import
the Scanner class. Now edit the main method to do the following:
(i) prompt for and input from the keyboard a suitable string
(ii) determine and output the length of your test string
(ii) determine and output the number of occurrences of the letter ’e’ in your string
Run your program for each of the following test strings:
(i) "In a minute there is time for decisions and revisions
which a minute will reverse."
(ii) "And in short, I was afraid."
Chỉnh sửa cuối:
