import java.util.Scanner;
public class Cosine
{
  public static void main(String args[])
  {
    Scanner kb = new Scanner(System.in);
    double first, next;
    System.out.print("Enter a number:");
    first = kb.nextDouble();
    boolean done = false;
    int count = 0;
    
    while(!done)
    {
      count++;
      next = Math.cos(first);
      System.out.println("Value = " + next);
      if(next == first)
      {
        done = true;
      }
      first = next;
    }
    System.out.println("Converged after " + count + " iterations.");
  }
}
