A simple question

A simple question

View Answers

March 23, 2009 at 2:16 AM

Hi friend,

Code to help in solving the problem :

import java.io.*;
class Square
{
public static void main(String[] args) throws IOException
{
boolean boolexit=true;
do
{

final double smallValue = 1.0E-14 ;

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the float value ");
double val = Double.parseDouble(br.readLine());


System.out.println("Do you want the (s)quare or square (r)oot of" + val);
String type=br.readLine();
if(type.equals("R") || type.equals("r"))
{


double N = val ;

if(N>0)
{
double guess = 1.00 ;

while ( Math.abs( N/(guess*guess) - 1.0 ) > smallValue )
{
// calculate a new value for the guess
guess = N/(2*guess) + guess/2 ;

}
System.out.println("The square root of "+N+" is "+ guess);
}
else
{
System.out.println("You must have a positive number for square root.");
System.out.println("Do you want the (s)quare or square (r)oot of" + val);
type=br.readLine();
}
}
if(type.equals("S") || type.equals("s"))
{
double sqval=val*val;
System.out.println("The number "+ val+" squared has the value "+ sqval);
}

System.out.println("Do you want to enter more data? y/n: y ");
String exit= br.readLine();
if(exit.equals("N") || exit.equals("n"))
{
boolexit=false;
}

}
while (boolexit);



}
}


Thanks









Related Tutorials/Questions & Answers:
A simple question - Java Beginners
A simple question   Design a program to calculate either the square of a number or the square root of a number and display the results. output should be like:- Enter a float value: 6.2 Do you want the (s)quare or square (r
simple program question
simple program question  how do i get a java program to take an input from the user and have it terminate by a period and not by pressing enter
Advertisements
Simple Question - JDBC
Simple Question  Respected Sir/Madam, I am R.Ragavendran.. Can I know the following syntax is valid or not? while(rs.next()) { <% <TR> } Because its not working for me.. It is throwing
Simple Java Question - Java Beginners
Simple Java Question  [color=#0040BF] Dear All, I have a huge text file with name animal.txt, I have the following sample data: >id1 lion >id2 horse cat >id3 mouse tiger I need to save the contents
Java simple question - Java Beginners
Java simple question  I have to design a program for a trucking company that has 7 trucks in its fleet. Each truck is identified by a number, 1-7. Each also has a maximum weight. Assign the max weight limit to each truck
JSF Simple question - Java Server Faces Questions
JSF Simple question  I have h:dataTable (with 10 position) i need write simple jsf file that represent only 5 position and on another page last 5 position . How can i proceed from first page to second
question
question   sir plz tell me what should i give in title box. just i want java program for the question typed in this area
question
question   sir plz tell me what should i give in title box. just i want java program for the question typed in this area
Question
Question   When there is an exception in my program how java runtime system handles
question
question  dear sir/madam my question is how to compare two text format in java..we are java beginners..so we need the complete source code for above mentioned question...we have to compare each and every word
question
question  Dear sir i had some typing mistake at previous question so its my humble request to let me know the steps to start the tomcat6 under the tomcat directory
question
question  Gud morning sir, I have asked u some question regarding jsp in saturaday for that i didnot find any answere in which u send me the some of the links.U have asked me the specify some details. There is a entity name
Question?
Question?  My question is how to: Add a menu bar to the program with a File menu. In the File menu, add a submenu (JMenuItem) called About. When the user clicks on the About menu item, display a JOptionPane message dialog
question
question  i need a simple jsp code for monthly salary calculation
question
question  i need a simple jsp code for monthly salary calculation
question
question  i need a simple javascript or jsp code to send message from one mail to another mail
question
question  Sir, please give me a simple jsp code to upload images to a folder
question
question  i need a simple code to display all employees on leave using jsp and mysql
question
question  i need a simple javascript or jsp code to send message from one mail to another mail
question
question  i need a simple jsp + mysql code for trigger after insert
question
question  please give me a simple program using bean + jsp + mysql
question
question  Sir, Please help me to develop a simple search engine model in java , send me some codes
question
question  good afternoon sir, please send me a simple Jsp or Java code to display a calendar with Indian public holidays,current date and time.It is very urgent,please consider and me as soon as possible
question
question  i need a simple jsp + mysql code to display all absentees.and please send,if have any option to send any notification message to user who forgot to mark attendance
question
question  Dear Sir, could you please send me a simple example of java and database connectivity with java and sql   Please visit the following link: JDBC Tutorials
question
question  Dear Sir, Could you please send me a simple and standard example including Java bean class , use of that bean class in JSP   .../usingbeansinjsp.shtml http://www.roseindia.net/jsp/simple-jsp-example/UseBean.shtml http
question
,jsp and simple java script.i don't know ajax
question
question  simple jsp code for login and validation using jsp and simple java script   // login.jsp <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> Insert title here
Question on pooling
Question on pooling  which server supports pooling?Application server or web server
This question in Jmeter
This question in Jmeter  hi..i want to send request(xml) 100 times but each time in request xml one element needs to change, otherwise request will be failed since its duplicate
Question on javascript
Question on javascript  This is not exactly what i wanted....If i enter in 2nd combobox as name of child then it should show child id in 1st combobox automatically and vice versa
C# question
Create a Solution by name Bank with Classes Account.cs, SavingsAccount.cs and savingsTest.cs to Demonstrate Abstract Classes in C#  1st question : Create a Solution by name Bank with Classes Account.cs, SavingsAccount.cs
question for c++
question for c++   write Program to swap between two numbers if first number is greater than second number and total of two numbers greater than 10
Inheritance question?
Inheritance question?  Q3)Create a class hierarchy as Company extended by AccountsDepartment. AccountsDepartment extended by AccountsReceivable... as AccountsPayable. please send the code of this question soon....plzzzzzzzz  
Inheritance question?
Inheritance question?  Q3)Create a class hierarchy as Company extended by AccountsDepartment. AccountsDepartment extended by AccountsReceivable... as AccountsPayable. please send the code of this question soon....plzzzzzzzz View
Question in Eclipse
Question in Eclipse   ** Hello EveryOne , L Have Question in Eclipse ?!! Question is : A.( The square class) Design a class named Square that contains : 1.A private instance variable side of type double 2.A no-argument
Question in Eclipse ??
Question in Eclipse ??  ** Hello EveryOne , L Have Question in Eclipse ?!! Question is : A.( The square class) Design a class named Square that contains : 1.A private instance variable side of type double 2.A no-argument
jsp question..
jsp question..  what should do in deployment descriptor after adding jstl jar files.. I am the the following message in console screen; The absolute cannot be resolved in either web.xml or the jar files deployed
jsp question..
jsp question..  what should do in deployment descriptor after adding jstl jar files.. I am the the following message in console screen; The absolute cannot be resolved in either web.xml or the jar files deployed
Question in Java ??
Question in Java ??   Welcome every One ,I have Q in Java : Write aprogram that print the falewing table using SQRT method in the Math Class? Number squrfoot
Question in Java ??
Question in Java ??  Welcome every One ,I have Q in Java : Write aprogram that print the falewing table using SQRT method in the Math Class? Number 0 ,2, . . . ,18,20 squrfoot 00000 1.4142 5.2426 5.4721
Question in Java ??
Question in Java ??  Welcome every One ,I have Q in Java : Write aprogram that print the falewing table using SQRT method in the Math Class? Number 0 ,2, . . . ,18,20 squrfoot 00000 1.4142 5.2426 5.4721
jsp question
jsp question   sir plz tell me how can I create a page which is similar to feedback form in which if one option is empty then other option is inaccessible. for example it consists of name address etc. if name field is not filled
jsp question
jsp question   sir plz tell me how can I create a page which is similar to feedback form in which if one option is empty then other option is inaccessible. for example it consists of name address etc. if name field is not filled
Question in eclipes ??!!
Question in eclipes ??!!  Hooole EveryOne I have Question in eclipes !!? Question is : The objectives of this lab are 1.Using the ââ?¬Å? thisââ?¬Â? reference. 2.Initializing class objects. 3.Using overloaded constructors
Question Java>?
Question Java>?  **ïâ??· Create a new class called Bank and in the main method use class Account (lab 4) to create an array of 10 accounts. ïâ??· Enter data for all accounts (account number,name, balance). ïâ??· Add
Question on java
Question on java  why java is not purely oop?   java is not purely OOP because 1.) Multiple Inheritance is not supported.ADS_TO_REPLACE_1 2.) It uses primitive data type. 3.) static method can be called without
Ajax Question
Ajax Question   I am having 3 fields in jsp they are Fieldname,Fieldtype,Required. If i enter as Fieldname studentid,Fieldtype as checkbox,Required as true(i.e., mandatory field as *).It should store their details in database
java question
java question   Create a class called Complex to perform arithmetic operations with complex numbers. 1- Use double variables to represent the fields of the class. 2- Provide a no-argument constructor with default values in case
Interview question.
Interview question.  Program to read the integers from the standard input (until it gets a negative number) and puts them in to an array.after that it calls process Array on the array,and then prints the content of the array

Ads