am15851
BAN USER/*
Remove all two zeros in the given string.
Example: a3409jd00dk000d
Output: a3409jddk000d
Note: If there are less/more than two zeros consecutive, it should not be replaced.
ideone.com/tYsRf
*/
import java.util.*;
import java.lang.*;
class Main
{
public static boolean check(int i, char[] s)
{
if ((i < s.length) && (s[i] == '0')) return true;
else return false;
}
public static void main (String[] args) throws java.lang.Exception
{
String a = "a3409jd00dk0000000d00e";
char[] s = a.toCharArray();
for(int i=0; i<s.length; i++)
{
if(s[i]== '0' && check(i+1, s))
{
if (!check(i+2, s))
System.out.println("Position of 2 consecutive 0's - i: "+i);
else
i = i+2;
}
}
}
}
ideone.com/n5aqx
import java.util.*;
import java.lang.*;
class Main
{
public static void pow(int a, int b)
{
double val1 = 1, val2 = 1;
if (b!=0)
{
int counter = Math.abs(b);
while(counter>0)
{
if (b<0)
{
val1 /= a;
}
else
{
val1 *= a;
}
counter--;
}
for(int i=0;i<a;i++)
{
val2 *= b;
}
}
else
{
val1 = 0;
val2 = 0;
}
System.out.println("Val1: "+val1);
System.out.println("Val2: "+Math.ceil(val2));
}
public static void main (String[] args) throws java.lang.Exception
{
pow(2, -4);
}
}
";
- am15851 August 25, 2012int level = 0;
String p;
for(int i=0; i<a.length();i++)
{
char c = a.charAt(i);
String s = Character.toString(c);
if( s.equals("{"))
{
level++;
int count = 0;
System.out.print(s+"\n");
while(count<level)
{
System.out.print(" ");
count++;
}
}
else if(s.equals(","))
{
int count = 0;
System.out.print(s+"\n");
while(count<level)
{
System.out.print(" ");
count++;
}
}
else if( s.equals("}"))
{level--;
int count = 0;
System.out.print("\n");
while(count<level)
{
System.out.print(" ");
count++;
}
System.out.print(s);
}
else
{
System.out.print(s);
}
}
}
}