-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram46.java
48 lines (43 loc) · 1.39 KB
/
Program46.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
45
46
47
48
/* Program 46
Write a program to overload the function hline(). Ask user if they want:
1. hline() - Print a line of 30 characters using "-".
2. hline(int n) - Print a line of 'n' characters using "*"
3. hline(int n, char ch) - Print a line of 'n' characters using character ch
11/06/24 */
import java.util.Scanner;
public class Program46 {
static void hline(int n, char ch) {
for (int i = 0; i < n; i++) {
System.out.print(ch);
}
System.out.println();
}
static void hline() {
hline(30, '-');
}
static void hline(int n) {
hline(n, '*');
}
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter choice\n0. no arguments\n1. 1 argument\n2. 2 arguments");
int choice = sc.nextInt();
switch (choice) {
case 0:
hline();
break;
case 1:
System.out.print("Enter number of characters: ");
hline(sc.nextInt());
break;
case 2:
System.out.print("Enter number of characters: ");
int n = sc.nextInt();
System.out.print("Enter character: ");
hline(n, sc.next().charAt(0));
break;
default:
System.out.println("Invalid choice");
}
}
}