Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package LeapYear;
- import java.util.Scanner;
- @interface KakumiriziDaud
- {
- String name() default " ";
- String email () default " ";
- }
- @KakumiriziDaud(name = "Kakumirizi Daud", email = "dkakumirizii@gmail.com")
- public class Sqrt {
- public void getTheSqrt( int n )
- {
- // double a = (eventually the main method will plug values into a)
- double a = (double) n;
- double x = 1;
- // For loop to get the square root value of the entered number.
- for( int i = 0; i < n; i++)
- {
- x = 0.5 * ( x+a / x );
- }
- System.out.println("The sqrt of " + a + " is " + x);
- System.out.println();
- System.out.println("Coders never Quit! Regardless weather the codes are running or not");
- }
- // Begin method main..
- public static void main(String[] args) {
- // Creating an object from "Scanner" to input data.
- Scanner Sa = new Scanner(System.in);
- Sqrt S = new Sqrt();
- //Asking the user to input the number we want to find its square root.
- System.out.println("Enter a positive number : ");
- int n = Sa.nextInt();
- // Calling the method that'll calculate the square root of the given number.
- S.getTheSqrt( n );
- } // End method main
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement