How to give the Value on Runtime in Java.
100% Working Code and Projects.
if you need any help about project and Application Contact Shelly at:+917888361589.
See the code below :-
Java Code :-
package CodingStartupAbheer;
import java.util.Scanner;
public class ScannerClass {
public static void main(String[] Abheer) {
Scanner q = new Scanner(System.in);
System.out.println("Enter any number");
int a = q.nextInt();
System.out.println("Enter any number");
int b = q.nextInt();
System.out.println("Enter your name");
String Abheer1=q.next();
int c = a + b;
int d = a - b;
int e = a * b;
int f = a / b;
int g = a % b;
System.out.println(Abheer1);
System.out.println("The Addition of two number you have entered is : " + c);
System.out.println("The Subtraction of two number you have entered is : " + d);
System.out.println("The Multiplication of two number you have entered is : " + e);
System.out.println("The Division of two number you have entered is : " + f);
System.out.println("The Modulas of two number you have entered is : " + g);
}
}
package CodingStartupAbheer;
import java.util.Scanner;
public class ScannerClass {
public static void main(String[] Abheer) {
Scanner q = new Scanner(System.in);
System.out.println("Enter any number");
int a = q.nextInt();
System.out.println("Enter any number");
int b = q.nextInt();
System.out.println("Enter your name");
String Abheer1=q.next();
int c = a + b;
int d = a - b;
int e = a * b;
int f = a / b;
int g = a % b;
System.out.println(Abheer1);
System.out.println("The Addition of two number you have entered is : " + c);
System.out.println("The Subtraction of two number you have entered is : " + d);
System.out.println("The Multiplication of two number you have entered is : " + e);
System.out.println("The Division of two number you have entered is : " + f);
System.out.println("The Modulas of two number you have entered is : " + g);
}
}
Output :-
Enter any number
12
Enter any number
12
Enter your name
Abheer
Abheer
The Addition of two number you have entered is : 24
The Subtraction of two number you have entered is : 0
The Multiplication of two number you have entered is : 144
The Division of two number you have entered is : 1
The Modulas of two number you have entered is : 0
12
Enter any number
12
Enter your name
Abheer
Abheer
The Addition of two number you have entered is : 24
The Subtraction of two number you have entered is : 0
The Multiplication of two number you have entered is : 144
The Division of two number you have entered is : 1
The Modulas of two number you have entered is : 0
Explanation :-
Here we use Scanner class of java to get the value on runtime.
Now in "Scanner q= new Scanner (System.in);" here 'q' is object name , 'new' is keyword which s use to allocate the memory to the object which is declared, 'System.in ' in this System is class which contains some coding and 'in' is object which helps to take the value on runtime.
Now, q.nextInt is used to define that we taking Integer value and from this we can get the value on runtime. Moving ahead, q.next() is used to take in String input on runtime.
0 Comments:
Post a Comment