Advertisement
Guest User

AMINE

a guest
May 30th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.89 KB | None | 0 0
  1. package tp_string;
  2.  
  3. public class TP_String {
  4.  
  5.     static void affiche1(String str){
  6.         for(int i=0; i<str.length(); i++)
  7.             System.out.println(str.charAt(i));
  8.     }
  9.    
  10.     static void affiche2(String str){
  11.         for(int i=str.length()-1; i>=0; i--){
  12.             System.out.println(str.charAt(i));
  13.         }
  14.     }
  15.    
  16.     static String extraire1(String str){
  17.         return str.substring(2, 8);
  18.     }
  19.    
  20.     static String extraire2(String str){
  21.         return str.substring(9, 12);
  22.     }
  23.    
  24.     static String extraire3(String str){
  25.         return str.substring(2, 5);
  26.     }
  27.    
  28.     static void construire1(String str){
  29.         System.out.println(extraire1(str).concat("ion"));
  30.     }
  31.    
  32.     static void construire2(String str){
  33.         System.out.println(str.substring(5, 9).concat("n"));
  34.     }
  35.    
  36.     static void construire3(String str){
  37.         System.out.println(str.substring(2, 6).concat("er"));
  38.     }
  39.    
  40.     static int rech1(String str, String recherche){
  41.         return str.indexOf(recherche);
  42.     }
  43.    
  44.     public static void main(String[] args) {
  45.        
  46.         String st="informatique";
  47.         affiche1(st);
  48.         System.out.println("");
  49.         affiche2(st);
  50.        
  51.         System.out.println("");
  52.         System.out.println(extraire1(st));
  53.         System.out.println(extraire2(st));
  54.         System.out.println(extraire3(st));
  55.        
  56.         System.out.println("");
  57.         construire1(st);
  58.         construire2(st);
  59.         construire3(st);
  60.        
  61.         System.out.println("");
  62.         System.out.println("index of ati : "+rech1(st, "ati"));
  63.         System.out.println("index of or : "+rech1(st, "or"));
  64.         System.out.println("index of info : "+rech1(st, "info"));
  65.         System.out.println("index of ss : "+rech1(st, "ss"));
  66.         System.out.println("index of q : "+rech1(st, "q"));
  67.        
  68.     }
  69.    
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement