JAI
BAN USERpublic class StringRotation
{
public static boolean isRotated(String s1, String s2,int rotationCount)
{
if(s1.length()!=s2.length())
{
return false;
}
String s=s1.substring(rotationCount)+s1.substring(0,rotationCount);
if(s.equals(s2))return true;
else
return false;
}
public static void main(String[] args)
{
System.out.println(isRotated("amazon","azonam",2));
}
}
import java.util.Random;
import java.util.Scanner;
public class ResourceAllocationWithDice
{
static int sum= 0;
static int[] rollRec = new int[6];
static Scanner sc=new Scanner(System.in);
public static void main(String[] args)
{
for (int i = 0; i < rollRec.length; i++)
{
sum=sum+rollRec[i];
}
Scanner sc = new Scanner(System.in);
char ch;
do
{ if(sum !=21)
{
System.out.print("To roll Dice press Y/y: ");
}
else
{
System.out.print("All reasource are allocated ");
System.exit(0);
}
ch =sc.nextLine().charAt(0); ;
Random r = new Random();
int Low = 1;
int High = 7;
int diceFaceValue = r.nextInt(High-Low) + Low;
System.out.println("Dice Face Value is : "+ diceFaceValue);
allocateResource(diceFaceValue);
}
while(ch=='Y' || ch=='y');
}
private static void allocateResource(int diceFaceValue)
{
if(rollRec[diceFaceValue-1]==0)
{
rollRec[diceFaceValue-1]=diceFaceValue;
sum =sum+diceFaceValue;
if(diceFaceValue==1)
{
System.out.println("Resource is assigned to 1st host");
}
else if(diceFaceValue==2)
{
System.out.println("Resource is assigned to 2nd host");
}
else if(diceFaceValue==3)
{
System.out.println("Resource is assigned to 3rd host");
}
else
{
System.out.println("Resource is assigned to "+ diceFaceValue+"th host");
}
}
else
{
if(diceFaceValue==1)
{
System.out.println("This Resource is Allready assigned to 1st host Please Roll dice again");
}
else if(diceFaceValue==2)
{
System.out.println("This Resource is Allready assigned to 2nd host Please Roll dice again");
}
else if(diceFaceValue==3)
{
System.out.println("This Resource is Allready assigned to 3rd host Please Roll dice again");
}
else
{
System.out.println("This Resource is Allready assigned to "+ diceFaceValue +"th host Please Roll dice again");
}
}
}
}
class Node
{
Node next;
int info;
Node(int data)
{
info = data;
next = null;
}
Node createList()
{
Node start = new Node(1);
Node mid1 = new Node(2);
Node mid2 = new Node(3);
Node mid3 = new Node(4);
Node end = new Node(5);
start.next=mid1;
mid1.next=mid2;
mid2.next=mid3;
mid3.next=end;
end.next=start;
return start;
}
void printList(Node head)
{
Node temp = head;
while (temp != null)
{
System.out.println(temp.info);
temp = temp.next;
}
}
void CheckForCircularLL(Node CircularLL)
{
Node slowPtr = CircularLL;
Node fastPtr = CircularLL;
while (slowPtr != null && fastPtr.next!=null)
{
slowPtr = slowPtr.next;
fastPtr = fastPtr.next.next;
if(slowPtr.info == fastPtr.info)
{
System.out.println("Link Linst is Circular");
System.exit(0);
}
}
System.out.println("Link Linst is NOT Circular");
}
}
public class CheckLinkListCircular
{
public static void main(String[] args)
{
Node ap = new Node(0);
System.out.println("Create Circular Linked List");
Node circularList = ap.createList();
System.out.println("Check whether Linked List is Circular : ");
System.out.println();
ap.CheckForCircularLL(circularList);
}
}
public class StringRotation
- JAI March 12, 2015{
public static boolean isRotated(String s1, String s2,int rotationCount)
{
if(s1.length()!=s2.length())
{
return false;
}
String s=s1.substring(rotationCount)+s1.substring(0,rotationCount);
if(s.equals(s2))return true;
else
return false;
}
public static void main(String[] args)
{
System.out.println(isRotated("amazon","azonam",2));
}
}