• Like
  • Save
Taller de string(java)
Upcoming SlideShare
Loading in...5
×
 

Taller de string(java)

on

  • 629 views

 

Statistics

Views

Total Views
629
Views on SlideShare
629
Embed Views
0

Actions

Likes
0
Downloads
2
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft Word

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Taller de string(java) Taller de string(java) Document Transcript

    • 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); }
    • 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); }}
    • -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------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"; }
    • 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";
    • } 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= " ";
    • 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"))
    • { 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);
    • }}