ashish.nimonkar93
BAN USERimport java.util.Scanner;
public class paranthesis {
public static void main(String[] args) {
String str;
int ans;
Scanner s = new Scanner(System.in);
paranthesis p=new paranthesis();
System.out.println("Enter a string");
str = s.nextLine();
ans = p.checkParanthesis(str);
System.out.println("answer is ->" + ans);
}
int checkParanthesis(String str){
int ans=0,str_index=0,pr=0;
if(str == null){
return(0);
}
else if(str != null){
while(str_index != str.length()){
if(str.charAt(str_index) == '('){
str_index++;
pr++;
}
else if(str.charAt(str_index) == ')'){
str_index++;
pr--;
ans++;
}
else{
str_index++;
}
}
if(pr == 0){
return(ans);
}
else if(pr != 0){
System.out.println("entered string is wrong!");
System.exit(0);
}
}
return(ans);
}
}
package temp2;
- ashish.nimonkar93 March 06, 2015import java.util.Scanner;
public class praiseq {
public static void main(String[] args) {
double num,p=1,q=1;
Scanner s = new Scanner(System.in);
System.out.println("enter a value");
num = s.nextInt();
do{
p++;
q=1;
do{
q++;
System.out.println("" + p + q);
if(Math.pow(p,q) == num){
System.out.println(num + "is in the form of p^q");
System.exit(0);
}
}while(Math.pow(p,q) < num);
}while(Math.pow(p,2) <= num);
if(Math.pow(p,q) != num){
System.out.println(num + "is NOT in the form of p^q");
System.exit(0);
}
}
}