Here is a snippet of my program asking users to enter their ships’ coordinates where I want the user input to be printed Bold.
import java.util.Scanner;
public class WorkArea{
public static void main(String[] args){
Scanner obj=new Scanner(System.in);
for(int j=0; j<2; j++){
System.out.println("\nPLAYER "+(j+1)+", ENTER YOUR SHIPS' COORDINATES.");
for(int i=0;i<5;i++){
System.out.println("Enter ship "+(i+1)+" location:");
String inp = obj.nextLine();
String[] arrOfStr = inp.split(" ");
int x = Integer.parseInt(arrOfStr[0]);
int y = Integer.parseInt(arrOfStr[1]);
}
}
}
}
For that I did import Font class and created object to implement that class like the following,
import java.awt.Font;
Font f=new Font("Monospaced", Font.BOLD, 18);e
right after that, how can i set the scanner object i.e obj into BOLD using this awt class and I want the coordinates to be printed BOLD on the console using Font object f. Do I need to create a static method to make the user input bold like the following or can i directly set the object into Bold.
public int setFont(Font f, Scanner obj) {
}
I have tried importing Font class and created object for the font class like the following,
import java.awt.Font;
Font f=new Font("Monospaced", Font.BOLD, 18);
System.out.println("Enter ship "+(i+1)+" location:");
obj.setFont(f);
String inp = obj.nextLine();
String[] arrOfStr = inp.split(" ");
int x = Integer.parseInt(arrOfStr[0]);
int y = Integer.parseInt(arrOfStr[1]);
}
public Font getFont(Scanner obj){
}
Expecting users input to be BOLD on the console and need clarification on how to define getFont() method or setFont() to make inputs BOLD.
Thanks
Priyadhanam Priyadhanam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.