-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path05JavaInputs&Outputs.java
44 lines (41 loc) · 1.63 KB
/
05JavaInputs&Outputs.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
37
38
39
40
41
42
43
44
import java.util.Scanner;
import java.io.DataInputStream;
class JavaInputs {
public static void main(String[] args) {
for (int i = 0; i < args.length; i++) {
System.out.println(args[i]);
}
Scanner sc = new Scanner(System.in);
System.out.println("Enter your name :");
String name = sc.nextLine();
System.out.println("Enter your roll number :");
int roll_num = sc.nextInt();
System.out.println("Enter your aggreegate percentage :");
float percentage = sc.nextFloat();
System.out.printf("Hi %s roll number %d, your aggregate percentage are %.2f.\n", name, roll_num, percentage);
sc.close();
/*
* ---This is old method for input stream and allowed only upto JDK 1.1.---
* ---In latest versions of java we can use BufferedReader instead of this.---
* float principalAmount;
* float rateOfInterest;
* int years;
* try {
* DataInputStream dis = new DataInputStream(System.in);
* System.out.print("Enter principal amount : ");
* System.out.flush();
* principalAmount = dis.readFloat();
* System.out.print("Enter rate of interest : ");
* System.out.flush();
* rateOfInterest = dis.readFloat();
* System.out.print("Enter number of years : ");
* System.out.flush();
* years = dis.readInt();
* float interestAmount = principalAmount * rateOfInterest * years;
* System.out.printf("The interest amount is %.2f.", interestAmount);
* } catch (Exception e) {
*
* }
*/
}
}