Guest User

mEmE TYpIng.

a guest
Oct 30th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.69 KB | None | 0 0
  1. /**
  2.  * This is most definitely the best program I've ever made!
  3.  */
  4. import java.util.*;
  5. public class TyPiNg
  6. {
  7.     static String convert(String in)
  8.     {
  9.         Random r1 = new Random(); //Creating an object of the Random class.
  10.         char[] a = in.toCharArray();
  11.         int upct = 0; //Variable to check for uppercase repetition.
  12.         int lowct = 0; //Variable to check for lowercase repetition.
  13.         a[0] = Character.toLowerCase(a[0]); //The first character must always be lowercase.
  14.         a[1] = Character.toUpperCase(a[1]); //The second character must always be uppercase.
  15.         //Modifying the rest of the sentence.
  16.         int i;
  17.         for(i=2;i<a.length;i++) //The first two characters have been modified already.
  18.         {
  19.             int num = r1.nextInt(2); //Getting either 0 or 1.
  20.             if(num == 0)
  21.             {
  22.                 a[i] = Character.toUpperCase(a[i]);
  23.                 upct++;
  24.                 if(upct == 2) //Checking if more than 2 uppercase characters occur together.
  25.                 {
  26.                     a[i] = Character.toLowerCase(a[i]);
  27.                     upct = 0;
  28.                 }
  29.             }
  30.             else
  31.             {
  32.                 a[i] = Character.toLowerCase(a[i]);
  33.                 lowct++;
  34.                 if(lowct == 2) //Checking if more than 2 lowercase characters occur together.
  35.                 {
  36.                     a[i] = Character.toUpperCase(a[i]);
  37.                     lowct = 0;
  38.                 }
  39.             }
  40.         }
  41.         //Joining the characters to form a string.
  42.         String b = "";
  43.         for(i=0;i<a.length;i++)
  44.             b += a[i];
  45.        
  46.         return b;
  47.     }
  48.    
  49.     public static void main(String[] args)
  50.     {
  51.         //Getting the user's input.
  52.         Scanner sc = new Scanner(System.in);
  53.         System.out.println("Please enter a word or a sentence.");
  54.         String a = sc.nextLine();
  55.         //Modifying the sentence and displaying it.
  56.         String res = convert(a);
  57.         System.out.println("Modified: ");
  58.         System.out.println(res);
  59.        
  60.         sc.close();
  61.     }
  62. }
Add Comment
Please, Sign In to add comment