Java programming question

Java programming question

View Answers

May 14, 2009 at 12:04 PM

Hi Friend,

Try the following code:

import java.io.*;
import java.util.*;
class Converter {
Scanner input=new Scanner(System.in);
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String unit="";
public void convertTemp(){
double temp=input.nextDouble();
System.out.print("Enter unit F or C: ");
try{
unit = br.readLine();
}
catch(Exception e){}
if((unit.equals("F"))||(unit.equals("f"))){
double c= (temp - 32) / 1.8;
System.out.println(c+" Celsius");
}
else if((unit.equals("C"))||(unit.equals("c"))){
double f=(temp*1.8+32);
System.out.println(f+" Fahrenheit");
input.close();
}
}
public void convertDistance(){
double dis=input.nextDouble();
System.out.print("Enter unit KM or Miles: ");
try{
unit = br.readLine();
}
catch(Exception e){}
if((unit.equals("KM"))||(unit.equals("km"))){
double miles = dis * 0.621;
System.out.println(miles+" Miles");
}
else if((unit.equals("Miles"))||(unit.equals("miles"))){
double km = dis/ 0.621;
System.out.println(km+" KM");
input.close();
}
}
public static void main(String[] args){
Converter convert=new Converter();
System.out.print("Enter the Temperature: ");
convert.convertTemp();
System.out.print("Enter the Distance: ");
convert.convertDistance();
}
}

Thanks









Related Tutorials/Questions & Answers:
Java Programming Question
Java Programming Question  write a program in java to show thread working with sleep and wait method   Hi Friend, Please visit the following links: Wait Method Sleep Method Thanks
programming question - Java Magazine
programming question  I have an SGVT map displaying on a phone emulator but then want to search for a given location on the map and display... tool. I need a java solution to this please
Advertisements
Java Programming Question
Java Programming Question  Write a program in Java to accept 10 different numbers an store it in text file.   Hi Friend, Try this: import java.io.*; import java.util.*; class AcceptNumbers{ public static void main
Java Programming Question
Java Programming Question  Write a program in Java to create a menu bar with the help of event handlers.   Hi Friend, Try this: import javax.swing.*; import java.awt.event.*; public class SwingMenuBar{ public
Assignment Question on java programming
Assignment Question on java programming  Can somone help me on this . Thx You are required to write a complete Java program for a simple grading system. At the beginning of the system, you need to input number of students
core java programming question
core java programming question  How to write a java program to list the customer names arrived to a restuarant on a particular date in alphabetical order with arguments as 1 filename yymmdd cust   Hi Friend, Try
Java Programming Question
Java Programming Question  Write a program in Java to create student information form an submit detail in database.   Hi Friend, Try this: import java.awt.*; import java.sql.*; import javax.swing.*; import
programming question - Java Beginners
programming question  Create a class named Movie that can be used with your video rental business. The Movie class should track the Motion Picture Association of America (MPAA) rating (eg., Rated G, PG-13, R), ID Number
Java programming question - Java Beginners
Java programming question   Give the definition of a class named Doctor whose objects are records for a clinic's doctors. This class will be derived class of the class SalariedEmployee that is given below the question. A Doctor
Java programming question - Java Beginners
Java programming question  I want to write a program that converts temperatures from celsius to fahrenheit and vice versa. It also converts kilometers to miles and vice versa using "methods".  Hi Friend, Try
socket programming question
socket programming question   can you respond to me the multiple clients chat application java code and a server that manages the clients using the socket programming in java
socket programming question
socket programming question   can you respond to me the multiple clients chat application java code and a server that manages the clients using the socket programming in java
socket programming question
socket programming question   can you respond to me the multiple clients chat application java code and a server that manages the clients using the socket programming in java
Java Programming
Java Programming  Hi, What is Java Programming? How I can learn Java Programming in one month? Thanks
java programming
in question Implement the program described above using the Java programming language...java programming   Companies and people often buy and sell stocks... programming method you want to accomplish this task. Both your stack and queue
java programming
in question Implement the program described above using the Java programming language...java programming   Companies and people often buy and sell stocks... programming method you want to accomplish this task. Both your stack and queue
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
programming java qus.
programming java qus.  write a import statement that import all the inner class of outer class .outer class must not be imported??   You must not ask similar question more then once. If it happens the user id
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
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
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
java question :)
java question :)  write java program to use vector in ArrayList with add, remove,sort   import java.util.Vector; public class... Element MUAYAD"); vc.add("Vector Element JAVA"); vc.add("Vector Element
programming - Java Beginners
programming for java beginners  How to start programming for java beginners
programming - Java Beginners
Start programming in Java  Programming in Java - Can any one please suggest how to start programming in Java
Java Programming
Java Programming  Write a Java program that prompt user to input a number of students in a class. Then, prompt user to input the studentÃ?¢ââ??‰â??¢s programming mark. Determine how many student get A+ and A for their grade
java programming
java programming  Write a Java program that prompt user to input a number of students in a class. Then, prompt user to input the studentâ??s programming mark. Determine how many student get A+ and A for their grade and how many
Java programming - Java Beginners
Java programming  hi sir, my question are as follows... hope u can solve my java programming problem.. Write a program to develop a class to hold... to : http://www.roseindia.net/java/beginners/index.shtml Thanks
Java programming
Java programming  What is the Role of OOP in java
Java programming
Java programming  What is the Role of OOP in java
java programming
java programming  how to write a coding for simple login form in netbeans
java programming
java programming  what is taxonomy tree why we use that concept in java   hierarchical taxonomy is a tree structure of classifications for a given set of objects
Java Programming
Java Programming  Using Java Frame form, help me develop a GPA calculating device, able to show Grade and points together, and using MySQL database
Java Programming
Java Programming  Using Java Frame form, help me develop a GPA calculating device, able to show Grade and points together, and using MySQL database
JAVA PROGRAMMING
JAVA PROGRAMMING  Write an OVERLOADED FUNCTION in java that swaps(interchanges) 2 user given numbers.(one integer and one float value) and displays the result after swapping. Invoke the function in a class
java programming
java programming  how to count the no. of constants in a user given string?? plzz help
java programming
java programming  Write a complete Java Program that correctly does the following: prints out first 1000 numbers (not including 1000) with a statement indicating whether it is even or not.. Output: Example Number 0 - Even
java programming
java programming  Hi friends, if i create one project what are the step i can make...... i need step by step procedure
java programming
java programming  WAP to calculate the sum of: x + x(square)/2 + x(cube)/3 +.......... x(to the power n)/n
java programming
java programming  supose i have a text field in java (like in gmail home page u have username field ) so i want to fill that field automatically by taking record from the database so is there any mechanism in java to handle
java programming
java programming  Hi friends i need simple login form coding using two labels,two textfields and two buttons in netbeans without using database connection. . if you know that logic please tell
java programming
java programming  Hi friend if you have any idea about this statement please tel me... String qry1="select * from custentry1 where custid='"+custno
java programming
java programming  Hi, do u have any idea about these lines? Hashtable<Integer,JLabel> labels = new Hashtable<Integer,JLabel>(); labels = new Hashtable<Integer,JLabel>
java programming
java programming  Hi friends, i need a simple login form source code. in that program i have two labels,two text fields and two buttons namely ok and cancel buttons. how to write for that one using netbeans without database
java Programming
java Programming  Based on the following algorithm, write a Java Program Start defining the MyClass class. Declare the class?s myField data field. Initialize the data field. Start defining the SetField() method. Set
Java Programming
Java Programming  Assume that bank maintains two kinds of accounts...://www.roseindia.net/tutorial/java/core/bankAccountApplication.html   thnk...://www.roseindia.net/answers/viewqa/Java-Beginners/27008-q-in-java.html
java programming
java programming  How can be uesd in graphiclly view for user inter (x,y) cordinate and show the output shart point to end point. java code,,????   import org.jfree.chart.*; import org.jfree.chart.plot.PlotOrientation
java programming
java programming  How can be uesd in graphiclly view for user inter (x,y) cordinate and show the output shart point to end point. java code,,????   import org.jfree.chart.*; import org.jfree.chart.plot.PlotOrientation
java programming
java programming  How can be uesd in graphiclly view for user inter (x,y) cordinate and show the output shart point to end point. java code,,????   import org.jfree.chart.*; import org.jfree.chart.plot.PlotOrientation

Ads