-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathj5UserInput.java
More file actions
30 lines (23 loc) · 1008 Bytes
/
j5UserInput.java
File metadata and controls
30 lines (23 loc) · 1008 Bytes
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
//j5_user_input
import java.util.Scanner;
public class j5UserInput{
public static void main(String[] args){
System.out.println("Input in Java");
Scanner sc = new Scanner(System.in); //read data from keyboard we define object once then we use in program\
System.out.print ("Enter scber 1 : ");
// int a = num.nextInt();
float a = sc.nextFloat();
System.out.print("\nEnter scber 2 : ");
// int b = num.nextInt();6
float b = sc.nextFloat();
float sum = a + b;
System.out.println("Sum of Two Numbers is : " + sum);
System.out.println("String Input");
Scanner sc2 = new Scanner(System.in);
String c = sc.next(); // if we not define input type it by default set to String
System.out.println(c); // but it only accept first word from input
// from input whole line we use
String str2 = sc2.nextLine();
System.out.println(str2);
}
}