Hey guys, by this post we're gonna learn how to do calculations with user inputs.
- As usual open the Eclipses
- Now import java util package
Coding :-
- First we wanna declare 2 variables.
- Next, display message to enter the first number.
- Create a scanner to get that number (SN :- When using scanners we get user inputs as Strings)
- Initialize that string to first variable.
- Do the same to the second number.
- Display the answer using System.out.println concept.
import java.util.*;
public class main {
public static void main(String []args){
int fnum;
int snum;
System.out.println("Enter first number");
Scanner s1 = new Scanner(System.in);
fnum = s1.nextInt();
System.out.println("Enter second number");
Scanner s2 = new Scanner(System.in);
snum = s2.nextInt();
System.out.println("Answer is" +fnum+snum);
}
}
( Don't try to copy this source code, understand and try this your own )
No comments:
Post a Comment