This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Convert uppercase to lowercase and vice-versa. | |
| import java.util.Scanner; | |
| class test { | |
| public static void main(String ar[]) { | |
| Scanner sc=new Scanner(System.in); | |
| System.out.println("Enter any string:"); | |
| String name = sc.nextLine(); | |
| String ans=""; | |
| // extract each character from user_id by charAt() method. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Using isUpperCase() to check whether name or any string entered by user is uppercase or not. | |
| import java.util.Scanner; | |
| class test | |
| { | |
| public static void main(String ar[]) | |
| { | |
| Scanner sc=new Scanner(System.in); | |
| System.out.println("Enter any string:"); | |
| String name = sc.nextLine(); | |
| // extract each character from name by charAt() method. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Using isLowerCase() to check whether name or any string entered by user is lowercase. | |
| import java.util.Scanner; | |
| class test { | |
| public static void main(String ar[]) { | |
| Scanner sc=new Scanner(System.in); | |
| System.out.println("Enter any string:"); | |
| String name = sc.nextLine(); | |
| // extract each character from user_id by charAt() method. | |
| for(int i=0;i<name.length();i++) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Using isLetterOrDigit() to check whether user_id or any string entered by user has a digit and/or letter and no other symbols or characters. | |
| import java.util.Scanner; | |
| class test { | |
| public static void main(String ar[]) { | |
| Scanner sc=new Scanner(System.in); | |
| boolean flag =false; // keep the switch/flag off in the beginning. | |
| System.out.println("Enter user_id:"); | |
| String user_id = sc.nextLine(); | |
| // extract each character from user_id by charAt() method. | |
| for(int i=0;i<user_id.length();i++) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Using isLetter() to check whether contact number or any integer input entered by user has a letter or not. | |
| import java.util.Scanner; | |
| class test { | |
| public static void main(String ar[]) { | |
| Scanner sc=new Scanner(System.in); | |
| boolean flag =false; // keep the switch/flag off in the beginning. | |
| System.out.println("Enter phone number:"); | |
| String number = sc.nextLine(); | |
| if(number.length()==10){ | |
| // extract each character from number by charAt() method. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Using isDigit() to check whether name or any string entered by user has a digit or not. | |
| import java.util.Scanner; | |
| class test { | |
| public static void main(String ar[]) { | |
| Scanner sc=new Scanner(System.in); | |
| boolean flag =false; // keep the switch/flag off in the beginning. | |
| System.out.println("Enter name:"); | |
| String name = sc.nextLine(); | |
| // extract each character from name by charAt() method. | |
| for(int i=0;i<name.length();i++) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Print the ASCII values for all the characters present in the input string entered by user | |
| import java.util.Scanner; | |
| class test { | |
| public static void main(String ar[]) { | |
| Scanner scan = new Scanner(System.in); | |
| System.out.println("Enter the string:"); | |
| String str = scan.next();// input a string. | |
| // As string is combination of different characters, we need to extrac | |
| // individual character and then print the ASCII respectivly. | |
| for(int i=0;i<str.length();i++) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ASCII code demo | |
| import java.util.Scanner; | |
| class test { | |
| public static void main(String ar[]) { | |
| Scanner scan = new Scanner(System.in); | |
| System.out.println("Enter the integer ASCII code:"); | |
| int value = scan.nextInt(); // input of Decimal value | |
| // Just covert the integer to character. | |
| char ch = (char)value; | |
| System.out.println("Character value for ASCII code: "+value+" is "+ch ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ASCII code demo | |
| import java.util.Scanner; | |
| class test { | |
| public static void main(String ar[]) { | |
| Scanner scan = new Scanner(System.in); | |
| System.out.println("Enter the character to check the ASCII code:"); | |
| char ch = scan.next().charAt(0); // input of character | |
| // We know that the (Decimal) integer value of a character is its ASCII value. | |
| // Hence, just coverting the character to integer will do the triick. | |
| int value = (int)ch; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Linear Search in Java -> for integers | |
| import java.util.Scanner; | |
| class test | |
| { | |
| public static void main(String ar[]) | |
| { | |
| Scanner scan = new Scanner(System.in); | |
| System.out.println("Enter the size of array:"); | |
| int size = scan.nextInt(); | |
| scan.nextLine(); //clear the buffer after integer input. |
NewerOlder