I have been having a lot of trouble with this code /: We have to create a code with 3 overloaded methods, display(), to display something N times. We have to call the method display() for displaying. In the main method, we have to have the user input an integer, a double number, a string, and the number of times they want each thing displayed. This is the expected output:
Please input an integer: 22
Please input a rational number: 3.6
Please input a String: Hello
Please input the number of display times: 3
22
22
22
3.6
3.6
3.6
Hello
Hello
Hello
Here is the code I have so far...I know it's nor correct but if somebody could help me out and tell me what I need to do, it would be very much appreciated!
import java.util.Scanner;
public class DisplayMultiple {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Please input an integer: ");
int num = input.nextInt();
System.out.print("Please input a rational number: ");
double b = input.nextDouble();
System.out.print("Please input a string: ");
String str = input.next();
System.out.print("Please input the number of display times: ");
int N = input.nextInt();
System.out.print(display(num, N));
System.out.print(display(b, N));
System.out.print(display(str, N));
}
public static void display(int num, int N) {
System.out.print(num);
}
public static void display(double b, int N) {
System.out.print(B)/>;
}
public static void display(String str, int N) {
System.out.print(str);
}
}

New Topic/Question
Reply



MultiQuote




|