Codemind Java Control Statements

BATHULA PRAVEEN (BP)
0

 


import java.util.*;
class Solution
{
public static void main(String args[])
{
String input;
int c=1,d=1,i=1,found=0;
int x[]=new int[10];
Scanner sc=new Scanner(System.in);

input=sc.next();
if(input.length()>10)
  System.out.println("-1");
else
{
char ch[]=input.toCharArray();
        x[Integer.parseInt(ch[0]+"")]++;
for(int j=1;j<ch.length;j++)
{
          int k=Integer.parseInt(ch[j]+"");
  int m=Integer.parseInt(ch[j-1]+"");

if(k==m)
{
  c++;
  d=0;
  i=0;
}
else if(k==m+1)
{
  c=0;
  i++;
  d=0;
}
else if(k==m-1)
{
c=0;
i=0;
d++;
}
else
{
   c=1;
   d=1;
   i=1;
}

if(c==3 || d==3 || i==3)
{
found=1;
break;
}
x[k]++;
}
if(found==0)
{
           for(int p=0;p<10;p++)
{
   if(x[p]>=5)
{
   found=1;
   break;
}
}
}
if(found==1)
System.out.println("FANCY NUMBER");
else    
System.out.println("NOT A FANCY NUMBER");
}
}
}


import java.util.*;
class Solution
{
    public static void ExcelColumn(int n) 
    {
          StringBuilder sb = new StringBuilder();
        while (n != 0) {
            int rem = n % 26;
            if (rem == 0) {
                rem += 26;
            }
            if (n >= rem) {
                n -= rem;
                sb.append((char) (rem + 64));
            }
            n /= 26;
        }
    System.out.println(sb.reverse().toString());
}
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        ExcelColumn(n);
    }
}


import java.util.*;
class Solution
{
    public static int prime(int n)
    {
        if(n==1)
        {
            return 0;
        }
        for(int i=2;i<(int)Math.sqrt(n)+1;i++)
        {
            if(n%i==0)
            {
                return 0;
            }
        }
        return 1;
    }
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        int c=0;
        for(int i=a;i<b+1;i++)
        {
            if(prime(i)==1)
            {
                c++;
            }
        }
        System.out.println(c);
    }
}


import java.util.*;
class Solution
{
    public static int LCM(int m,int n)
    {
        int max=m>n?m:n;
        int lcm=max;
        while(true)
        {
            if(lcm%m==0 && lcm%n==0)
                break;
            
            lcm=lcm+max;
        }
        return lcm;
    }
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        int t,A,B,K;
        long N;
        t=sc.nextInt();
        while(t-- > 0)
        {
            N=sc.nextLong();
            A=sc.nextInt();
            B=sc.nextInt();
            K=sc.nextInt();
            int count=(int)N/A + (int)N/B - (int)N/LCM(A,B);
            if(count>=K)
            System.out.println("Win");
            else
            System.out.println("Lose");
        }
    }
}


import java.util.*;
class Solution
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int f=1;
        for(int i=1;i*i<=n;i++)
        {
            if(i*i==n)
            {
                System.out.println("True");
                f=0;
                break;
            }
        }
        if(f!=0)
        {
            System.out.println("False");
        }
       
    }
}


import java.util.*;
class Solution 
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        float s=0;
        for(float i=1;i<n+1;i++)
        {
            s=s+(1/i);
        }
        System.out.format("%.2f",s);
    }
}


import java.util.*;
class swl
{
    static int is_prime(int n)
    {
        if(n==1)
        {
            return 0;
        }
        else
        {
            for(int i=2;i<=Math.sqrt(n);i++)
            {
                if(n%i==0)
                {
                    return 0;
                }
            }
            return 1;
        }
    }
    static int is_palindrome(int m)
    {
        int a = m;
        int s=0,b;
        while(m!=0)
        {
            b=m%10;
            s=s*10+b;
            m=m/10;
        }
        if(a==s)
        {
            return 1;
        }
        else
        {
            return 0;
        }
    }
    public static void main(String asd[])
    {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        scan.close();
        for(int i=n+1;i!=0;i++)
        {
            if(is_prime(i)==1)
            {
                if(is_palindrome(i)==1)
                {
                    System.out.print(i);
                    break;
                }
            }
        }
        
    }
}

import java.util.*;
class Solution
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int a,b,c;
        a=0;
        b=1;
        System.out.format("%d %d ",a,b);
        for(int i=1;i<n-1;i++)
        {
            c=a+b;
            a=b;
            b=c;
            System.out.format("%d ",c);
        }
    }
}

Post a Comment

0Comments

Post a Comment (0)