Related: First Java Program | Install Java | Keyboard input in Java
How to calculate with Java
import java.io.*;
class fourth
{
public static void main(String args[])throws IOException
{
Integer r;
Float n,add,sub,mul,div,empty;
String s1;
String s2;
InputStreamReader in=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(in);
System.out.print("Enter first value");
s1=br.readLine();
System.out.print("Push second value");
s2=br.readLine();
r=Integer.valueOf(s1);
n=Float.valueOf(s2);
add=r+n;
sub=r-n;
mul=r*n;
div=r/n;
System.out.println("add of two variable"+add);
System.out.println("sub of two variable"+sub);
System.out.println("mul of two variable"+mul);
System.out.println("divi of two variable"+div);
empty=add;
add=mul;
mul=empty;
empty=sub;
sub=div;
div=empty;
System.out.println("after changing/Swapping");
System.out.println("add of two Variable"+add);
System.out.println("sub of two variable"+sub);
System.out.println("mult of two variable"+mul);
System.out.println("divi of two variable"+div);
}
}
Here in the above code when you run it it will show like this screenshot:-

When you run with cmd then this will ask you to enter first value and then second value and finally it will print all the result after the calculation. How to calculate with Java new codes coming soon.
0 Comments