cho mình hỏi về java

KnightOfEmpire

Mr & Ms Pac-Man
Tham gia ngày
12/6/06
Bài viết
206
Reaction score
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 :D

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:
bạn mới học ko mày mò làm mà đi nhờ thế này thì về sau khó hơn làm thế nào ?
mình dịch tạm hộ nhé:
1: Viết 1 ứng dụng java với 1 phương thức là TimeConverter, làm những việc sau:
i: cho nhập 1 số nguyên là giá trị cho số giây ( dùng Scanner hoặc BufferedReader - google để xem cách sử dụng)
ii: In ra giá trị tương đương dưới dạng giờ: phút: giây, nếu phút hoặc giây nhỏ hơn 10 thì phải có 0 ở trc (01,02...)
Gợi ý: trong java, ví dụ nhập 276 giây, 276/60 -> cho 4 , 276%60 cho 36 --> 276 giây = 00:04:36 ...

2: dài quá ngại :'>
 
cảm ơn bối bối, cái 1 thì mình làm dc rồi còn cái 2 thôi >.< ko hiểu đề nó thế nào, ko biết có phải làm tiếp theo của câu 1 ko.
 
bài thứ 2 là về string, không liên quan gì đến bài 1
đoạn đầu là nó giới thiệu cho mình về biến kiểu string
nếu bạn biết rồi thì có thể bỏ qua

đề bài là cho 2 xâu như sau, mỗi xâu yêu cầu làm 3 việc:
(i) "In a minute there is time for decisions and revisions
which a minute will reverse."
(ii) "And in short, I was afraid."
(i) chịu :">
(ii) tính độ dài của xâu (cái này trong đoạn đầu nó có nói, nếu bạn không hiểu thì có thể đọc)
(iii) đếm xem kí tự 'e' xuất hiện trong xâu bao nhiêu lần (cũng có nói trong đoạn đầu)
 
cảm ơn mọi người, mình hiểu rồi :D
 
edited

nhờ mod xóa hộ mình topic này. cảm ơn :D
 
Chỉnh sửa cuối:
Back
Top