Sei sulla pagina 1di 2

JAVA

G11 Revision Sheet



Reading material to be revised p48 -57


Check summary on p60
Reading material to be covered 82-95
Check summary on p96

Any topics you have difficulty on check
http://www.tutorialspoint.com/java/index.htm
Use the search area and type the page topic e.g. Manipulating
characters

Question

Answer

The result should be 9 also count the blank


String str1 = "Mr Nathan";
System.out.print(str1.length( )); spaces


System.out.print(Math.round(2.4));
The result should be 2
System.out.print(Math.round(6.6));
The result should be 7
Which of the Math.class return a double
Math.random()
result? Example 1.0
Math.ceil( )
Math.floor( )
Math.pow( )
Math.sqrt( )
Which of the Math.class return an Integer or Math.round( )
long result? Example 1
I for(i=1;i<6;i++)
12345
{
System.out.println(i);

}

both i<6 and i<=5 would produce the same
results
int i;
11 12 13 14 15 16 17 18 19 20
for(i=20;i>10;i--)
{
System.out.println(i);

}
both >=11 and >10 would produce the
same results

>10
>=10

Would achieve different results

>=10 would receive an additional


iteration

Which Math.class take a single argument?

Math.sqrt ( )
Math.floor( )
Math.ceil( )

Which Math.class take a double argument?



startsWith( )

Math.pow
) or false
Will
return ( t,rue
e.g.

Nathaniel Haswell
startsWith(Nathaniel); Result true
startsWith(Haswell); Result false
The argument is the string you want to
join e.g.

txt1.concat( txt2);

concat( )
Joins strings together

substring() returns a new string that is a


substring of this string.

1. ( ) will start at the index value and


follow to the end of the String
2. (0,4 ) will start at index zero and
end on 4. (not including index 4)


http://www.tutorialspoint.com/java/java_s
tring_substring.htm

Character case of string can be changed
using: toUpperCase( )
or
toLowerCase( )

trim() cuts blank space before and
after
charAt() Selects a character by
index position
replace(,) Will exchange a character
isEmpty() Will return true if the
String is empty


substring can accept a single argument or


a double

single will start at the given number point

double will start and end at the given
points .

Example:
String a= "mr nathan";

System.out.println(a.toUpperCase());

Using the String str



1. If (str.isEmpty()) = mr
nathan ;
2. System.out.print(str.trim() );
3. System.out.print(str.charAt(1) );
4. String txt= str.replace('a','u');

System.out.println(txt);

Potrebbero piacerti anche