Zmienne w Javie
14 July 2008
Comments
Rzutowanie typów umożliwia ręczną konwersję jednego typu w drugi. Główna forma rzutowania ma postać:
(typ docelowy) wyrażenie
Przykład:
public
class test
{
public static void main (String args[])
{
double a = 5;
double b = 3;
int c = (int) (a/b);
System.out.println(c);
System.out.println(a/b);
}
}
Stringi czyli łańcuchy tekstowe w Javie są obiektami i ich "definiowanie" przebiega tak jak dla zwykłych obiektów:
public
class test
{
public static void main (String args[])
{
String str = new String("To jest tekst");
System.out.println(str);
}
}
public
class test
{
public static void main (String args[])
{
String str1 = new String("To jest tekst");
String str2 = new String("To jest tekst");
if (str1.equals(str2))
{
System.out.println("oba stringi są identyczne");
}
System.out.println(str1.length());
System.out.println(str1.indexOf("jest"));
}
}
RkBlog
Comment article