Java ортасында жолдарды өңдеу Әдістемелік нұсқау


indexOfжәнеlastIndexOf әдістерінің қолданылу



бет4/7
Дата06.01.2022
өлшемі55,22 Kb.
#14495
1   2   3   4   5   6   7
indexOfжәнеlastIndexOf әдістерінің қолданылу

Мысал 4.


class indexOfDemo {

public static void main(String args[]) {

String s = "Now is the time for all good men " +

"to come to the aid of their country " +

"and pay their due taxes.";

System.out.println(s);

System.out.println("indexOf(t) = " + s.indexOf('t’));

System.out.println("lastlndexOf(t)= " +s.lastlndexOf('t’));

System.out.println("indexOf(the) = " + s.indexOf("the"));

System.out.println("lastlndexOf(the) = " + s.lastlndexOf("the"));

System.out.println("indexOf(t, 10) = " + s.indexOf('t’ , 10));

System.out.println("lastlndexOf(t, 50) = " + s.lastlndexOf('t’ , 50));

System.out.println("indexOf(the, 10) = " + s.indexOf("the", 10));

System.out.println("lastlndexOf(the, 50) = " + s.lastlndexOf("the", 50));

}

}

Программа нәтижесі



Now is the time for all good men to come to the aid of their country

and pay their due taxes.

indexOf(t) = 7

lastlndexOf(t) = 87

indexOf(the) = 7

lastlndexOf(the) = 77

indexОf(t, 10) = 11

lastlndexОf(t, 50) = 44

indexОf(the, 10) = 44

lastlndexОf(the, 50) = 44





Достарыңызбен бөлісу:
1   2   3   4   5   6   7




©emirsaba.org 2024
әкімшілігінің қараңыз

    Басты бет