Advertisement
Guest User

Untitled

a guest
Oct 7th, 2015
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. package uf1;
  2. import java.util.Scanner;
  3. public class A01 {
  4.  
  5. public static void main(String[] args) {
  6. // TODO Auto-generated method stub
  7.  
  8. Scanner sc = new Scanner(System.in);
  9. String abcmin = "abcdefghijklmnopqrstuvwxyz";
  10. String abcmay= "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  11. String missatge;
  12. int numsecret;
  13. String xifrat="";
  14.  
  15. System.out.println("Digues el teu missatge:");
  16. missatge=sc.nextLine();
  17.  
  18. System.out.println("Digues el numero clau:");
  19. numsecret=sc.nextInt();
  20.  
  21.  
  22. int i;
  23. int j;
  24.  
  25. for (i=0;i< missatge.length(); i++)
  26. {
  27. for(j=0; j<abcmay.length(); j++)
  28. {
  29. if(missatge.charAt(i)== abcmay.charAt(j)) // mirem si el caracter k llegim es troba al abecedariMayus
  30. {
  31. if(j+numsecret >= abcmay.length())
  32. {
  33. xifrat += abcmay.charAt((j+numsecret)%abcmay.length());
  34. }
  35. else
  36. {
  37. xifrat += abcmay.charAt(j+numsecret);
  38. }
  39. }
  40. else if(missatge.charAt(i)== abcmin.charAt(j)) // mirem si el caracter k llegim es troba al abecedariMinus
  41. {
  42. if(j+numsecret >= abcmin.length())
  43. {
  44. xifrat += abcmin.charAt((j+numsecret)%abcmin.length());
  45. }
  46. else
  47. {
  48. xifrat += abcmin.charAt(j+numsecret);
  49. }
  50. }
  51.  
  52. }
  53.  
  54. System.out.println(xifrat);
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement