Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * This is most definitely the best program I've ever made!
- */
- import java.util.*;
- public class TyPiNg
- {
- static String convert(String in)
- {
- Random r1 = new Random(); //Creating an object of the Random class.
- char[] a = in.toCharArray();
- int upct = 0; //Variable to check for uppercase repetition.
- int lowct = 0; //Variable to check for lowercase repetition.
- a[0] = Character.toLowerCase(a[0]); //The first character must always be lowercase.
- a[1] = Character.toUpperCase(a[1]); //The second character must always be uppercase.
- //Modifying the rest of the sentence.
- int i;
- for(i=2;i<a.length;i++) //The first two characters have been modified already.
- {
- int num = r1.nextInt(2); //Getting either 0 or 1.
- if(num == 0)
- {
- a[i] = Character.toUpperCase(a[i]);
- upct++;
- if(upct == 2) //Checking if more than 2 uppercase characters occur together.
- {
- a[i] = Character.toLowerCase(a[i]);
- upct = 0;
- }
- }
- else
- {
- a[i] = Character.toLowerCase(a[i]);
- lowct++;
- if(lowct == 2) //Checking if more than 2 lowercase characters occur together.
- {
- a[i] = Character.toUpperCase(a[i]);
- lowct = 0;
- }
- }
- }
- //Joining the characters to form a string.
- String b = "";
- for(i=0;i<a.length;i++)
- b += a[i];
- return b;
- }
- public static void main(String[] args)
- {
- //Getting the user's input.
- Scanner sc = new Scanner(System.in);
- System.out.println("Please enter a word or a sentence.");
- String a = sc.nextLine();
- //Modifying the sentence and displaying it.
- String res = convert(a);
- System.out.println("Modified: ");
- System.out.println(res);
- sc.close();
- }
- }
Add Comment
Please, Sign In to add comment