import java.util.*;
/*
*
* A string consists of parenthesis and letters. Write a program to validate all the parenthesis.
* Ignore the letters.eg.
* ((alf)ls) – valid
* )(dkk)() – invalid
*/
public class StringI_1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter string :- ");
String str = sc.nextLine();
System.out.println("Entered string is :- " + str);
int countOpen = 0 ;
int countClose =0 ;
int sizeOfString = str.length();
if(str == null || sizeOfString == 0){
System.out.println("String is Empty");
System.exit(0);
}
if (str.charAt(0) != '(' && str.charAt(sizeOfString - 1) != ')' ){
System.out.println("First : Invalid String");
System.exit(0);
}
/*else
System.out.println("valid");*/
for(int i = 0 ; i< sizeOfString ; i++){
if(str.charAt(i) == '(' && i!=(sizeOfString-1) ){
if( str.charAt(i+1) == ')' ){
System.out.println("Second :Invalid String ");
System.exit(0);
}else{
countOpen++;
System.out.println("countOpen :- " + countOpen +" "+ str.charAt(i));
}
}else {
if(str.charAt(i) == ')' ){ //&& str.charAt(i+1) !=')'
countClose++;
System.out.println("countClose :- " + countClose +" "+ str.charAt(i));
}
}
}
if(countOpen == countClose){
System.out.println("Valid string");
}else{
System.out.println("Third : Invalid String");
}
}
}
Explore the Latest in Tech & Automation: Android, iOS, Mobile Testing with Appium, Web Automation using Selenium, Python & Java Programming, Robot Framework, Shell & PowerShell Scripting, QA Tools, Spring Boot Development, Agentic AI Innovations, Free Software Resources, and Expert Tips on Designing Scalable Automation Frameworks.
Thursday, January 15, 2015
Java : A string consists of parenthesis and letters. Write a program to validate all the parenthesis.
Thursday, December 25, 2014
Japanese Input Method Editor(IME)
What is IME?
An IME is a program that allows computer users to enter complex characters and symbols, such as Japanese languages (usually but not limited to East Asian ones) that are made up of thousands of characters that can't fit on a standard keyboard.
Why we need IME?
Each language of CCJK has lots of characters, we cannot map all of them on standard keyboard.
Composition Window :-
Contains the collection of characters that the user has composed with the IME. These characters are drawn by the IME on top of the application. When the user notifies the IME that the composition string is satisfactory, the IME then sends the composition string to the application via a series of WM_CHAR messages.
Candidate Window :-
When the user has entered a valid pronunciation, the IME displays a list of candidate characters that all match the given pronunciation. The user then selects the intended character from this list, and the IME adds this character to the Composition Window display.
- Click on the Input Mode button (an "A" by default) will allow you to select the Input Mode:
- The IME Pad button will bring up the IME Features menu which includes a soft-keyboard which allows direct input of hiragana and katakana:
Shortcuts used to toggle b/w IME :-
¨ ALT-~ (tilde): Cycles between kana and direct input mode
¨ ALT-SHIFT: Cycles through available languages
¨ ALT-CAPS_LOCK: Switches to katakana input mode
¨ CTRL-CAPS_LOCK: Switches to hiragana input mode
Saturday, August 23, 2014
Java : Program to reversing a string
public class ReverseString {
/**
* @param args
*/
public static void main(String[] args) {
//String[] name = new String[10];
String name , rev = "";
Scanner in = new Scanner(System.in);
System.out.println("Enter the string for reversal :- ");
name = in.nextLine();
int len = name.length();
for(int i = len-1;i>=0;i--){
rev = rev + name.charAt(i);
}
System.out.println(rev);
}
}
Java : Program swapping two numbers without using third variable
public class SwapTwoNo {
/**
* @param args
*/
public static void swap(int a , int b){
a = b+a;
b = a-b;
a = a-b;
System.out.println("Values of a and b after swap := " + a +" "+ b + " respectively");
}
public static void main(String[] args) {
int a = 5;
int b = 6;
System.out.println("Values of a and b before swap := " + a +" "+ b + " respectively");
swap(a,b);
}
}
Subscribe to:
Posts (Atom)
Linux: How to change OS language via terminal?
In this post , I will be talking about how to change language of Linux OS from Terminal . If you are not a frequent user of Linux and str...
-
How to change language of device using commandLine Changing language in Android device on-the fly is needed when we are running or exe...
-
How to find the UDID of Android Device What is UDID : It stands for Unique Device Identifier. UDID is required duri...
-
How to get the package name of Android application There are multiple ways in which we can obtain the package name of Android .apk file. ...




