-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDay5.java
More file actions
48 lines (39 loc) · 1.53 KB
/
Day5.java
File metadata and controls
48 lines (39 loc) · 1.53 KB
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
45
46
47
48
// ---------------------------------------------------
// Author : Benjamin Kataliko Viranga
// Community : Stunt Business
// Community website : www.stuntbusiness.com
//
// 30 Days - Q&A Java basic
// Day 5 : Challenge III - Input and user functions using the Scanner and args util from java
// Day 5 | IG : https://www.instagram.com/benjivrik/
// ----------------------------------------------------
// what would be the output of this program ?
import java.util.Scanner;
public class Day5
{
public static void main(String[] args)
{
int user_value = 0;
// the size must be 1
if(args.length == 0 || args.length > 1)
{
// Only expect one Integer for the program to run
System.out.println("You should have entered one parameter in the command line.");
// initialize your scanner
Scanner sc = new Scanner(System.in);
// Request the user to enter a value;
System.out.printf("Please enter an integer : ");
user_value = sc.nextInt();
sc.close();
}
else
{
user_value = Integer.parseInt(args[0]); //get the first parameter of the command line
}
// display the value entered by the user
System.out.printf("\nYou entered : %d.\n", user_value);
// return the double of the parameter
System.out.println("The double of the parameter is : " + Day3.double_parameter(user_value));
System.out.println("End of program.");
}
}