-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscan.java
36 lines (22 loc) · 1.01 KB
/
scan.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import java.util.Scanner;
public class scan{
public static void main (String[] args){
int num1,num2;
Scanner kb = new Scanner(System.in); // here kb is just a name // Scanner is class new object is created //
System.out.println("Please Enter the number 1 : ");
num1 = kb.nextInt(); // for integer //rem Int not int
//.nextDouble .nextFloat .nextLne(for string) .nextByte .nextChar etc
System.out.println("Please Enter the number 2 : ");
num2 = kb.nextInt();
double avg = (num1+num2)/2.0;
System.out.println("Average of number is : " + avg);
// playing with String
kb.nextLine(); //to consume the enter of premitive data type int that we have used earlier // kb.nextInt(); it takes enter also
String name,surname;
System.out.println("Please Enter your first name : ");
name = kb.nextLine();
System.out.println("Please Enter your surname : ");
surname = kb.nextLine();
System.out.println(name + " " + surname);
}
}