Changing fahrenheit in celsius java programming language.
Dear student if you practice with source so it will very simple way to learn coding .
here you will get web developing code like javascript ,html ,css,
and also java programming language .
Please share this side,s link to your friends and relative.
Please see this video tutorial on full resolutions .
so friend first we need to create a class then
we will also create his mean method in this class because it is not
very dynamic program .
then we will get a input from user for this we need to create a
scanner class as i show in this code-source for choosing option then
we will create a swicth and if our case 1, so for we need to create all task for those case
and after this break keyword because if your case match so programm will break here and not excuse all program
again like this we need to create this all case but only we need to change this all case ,s task because in every case we need to different task and in the last we creat our default value because if any case will not match so in this case itthis program will so a default value .
how to handle exception :
for this on the frist block we need to create try keyword and below of this block we need to use of catch keyword and small bracket in this
bracket we create to exception name and a object and again curly bracket open and in this bracket we show his exception cause
you can use of this source-code through copy and paste.
import java.util.InputMismatchException;
import java.util.Scanner;
// class name Animals is
class Animals{
//main method
public static void main(String args[]){
/* suppose if any person enter any
String type values on the place of integer
in this case this program will throw a
exception"InputMismatchException" so we need
to Handle of this exception with the help
of try and catch
*/try{
// first here we take a input for fahrenheit , through Scanner class
Scanner in= new Scanner(System.in);
System.out.println("Enter your temperature in fahrenheit ");
int fahrenheit = in.nextInt();
/*here we used of this formula
((fahrenheit -32)/1.8)
for changing in celsius temperature,
and here i used to float for accuracy with type-casting
*/
float changing=(float)((fahrenheit -32)/1.8);
// i printed this values
System.out.println("your temperature in celsius " +changing);
}
catch (InputMismatchException e) {
/*when will be enter wrong type
input then it will so
*/
System.out.println("please Enter right input . please try again ");
}
}
}
Comments
Post a Comment