Your SlideShare is downloading. ×

Taller de string(java)

391

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
391
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. import javax.swing.*;public class ConcatenacionString{ public static void main(String args[]){ String s1=new String("Feliz "); String s2=new String("Cumpleaños"); String salida="s1= "+s1+"ns2="+s2; salida+="nnResultado De of s1.concat(s2)="+s1.concat(s2); salida+="ns1 Despues De La Concatenacion ="+s1; JOptionPane.showMessageDialog(null,salida,"El metodo Concat DeString",JOptionPane.INFORMATION_MESSAGE); System.exit(0); }}-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------import javax.swing.*;public class StringDemo{ public static void main(String[]args){ String palindrome="Dot saw I was Tod"; int len=palindrome.length(); char[] tempCharArray=new char[len]; char[] charArray=new char[len]; for(int i=0;i<len;i++) { tempCharArray[i]=palindrome.charAt(i); }
  • 2. for(int j=0;j<len;j++) { charArray[j]=tempCharArray[len - 1 - j]; } String reversePalindrome=new String(charArray); JOptionPane.showMessageDialog(null,reversePalindrome); for(int j=0;j<len;j++) { (if(tempCharArray[i]==charArray[i]) { contador ++; } } }}-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------import javax.swing.*;public class indexOfEjemplo1{ public static void main(String args[]){ String cadena="Codigo Fuente en Java"; int index =cadena.indexOf("Java"); JOptionPane.showMessageDialog(null,index); }}
  • 3. -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------import javax.swing.*;public class indexOfEjemplo2{ public static void main(String args[])throws Exception{ String cadena="Codigo Fuente en Java y aca aparece otra vez Java"; int index =cadena.indexOf("Java"); JOptionPane.showMessageDialog(null,index); index=cadena.indexOf("Java",index+1); JOptionPane.showMessageDialog(null,index); }}-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------import javax.swing.JOptionPane;public class CompararString{ public static void main(String args[]){ String s1=new String("hola"); String s2="adios"; String s3="Feliz Cumpleaños"; String s4="feliz cumpleaños"; String salida="s1= "+s1+"ns2= "+s2+"ns3= "+s3+"ns4= "+s4+"nn"; if(s1.equals( "hola")) { salida+="s1 Es Igual A "hola"n"; }
  • 4. else { salida+="s1 Es Distinto A "hola"n"; } if(s1=="hola") { salida+="s1 Es Igual A "hola"n"; } else { salida+="s1 Es Distinto A "hola"n"; } if(s3.equalsIgnoreCase(s4)) { salida+="s3 Es Igual A s4n"; } else { salida+="s3 Es Distinta De s4n"; } salida+="ns1.compareTo( s2 ) Es "+s1.compareTo( s2 )+"ns2.compareTo( s1 ) Es"+s2.compareTo( s1 )+"ns1.compareTo( s1 ) Es "+s1.compareTo( s1 )+"ns3.compareTo( s4 ) Es"+s3.compareTo( s4 )+"ns4.compareTo( s3 ) Es"+s4.compareTo( s3 )+"nn"; if(s3.regionMatches(0,s4,0,5)) { salida+="Los Primeros 5 Caracteres De s3 Y s4 Concuerdann";
  • 5. } else { salida+="Los Primeros 5 Caracteres De s3 Y s4 No Concuerdann"; } if(s3.regionMatches( true,0,s4,0,5)) { salida+="Los Primeros 5 Caracteres De s3 Y s4 Concuerdan"; } else { salida+="Los Primeros 5 Caracteres de s3 y s4 no Concuerdan"; } JOptionPane.showMessageDialog(null,salida,"Comparaciones EntreCadenas",JOptionPane.INFORMATION_MESSAGE); System.exit(0); }}-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------importjavax.swing.*;public class CompararApellidos{ public static void main(String args[]){ String apellido1= " "; String apellido2= " "; String Salida= " ";
  • 6. apellido1=JOptionPane.showInputDialog(null,"Ingrese El Primer Apellido"); apellido2=JOptionPane.showInputDialog(null,"Ingrese El Segundo Apellido"); if(apellido1.equals(apellido2)) { JOptionPane.showMessageDialog(null,"Son Iguales"); } else { JOptionPane.showMessageDialog(null,"Son Diferentes"); } System.exit(0); }}-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------import javax.swing.JOptionPane;public class UsuarioYContraseña{ public static void main(String args[]){ String usuario=" "; String contra=" "; int cont=0; int contador=0; do { usuario=JOptionPane.showInputDialog(null,"Digite El Usuario"); if(usuario.equalsIgnoreCase("Rigo"))
  • 7. { do { contra=JOptionPane.showInputDialog(null,"Digite ElPassword"); if(contra.equals("VeGa")) { JOptionPane.showMessageDialog(null,"Bienvenido"); } else { JOptionPane.showMessageDialog(null,"Error DeContraseña"); cont++; } } while(cont<3); } else { JOptionPane.showMessageDialog(null,"Erro De Usuario"); contador++; } } while(contador<3); System.exit(0);
  • 8. }}

×