Basically I've got to write a program which generates a 10 ×10 multiplication table, but only shows those entries which are greater than a value entered by the user (such as 50, but obviously I need to test a number of other ones). Entries which are less than or equal to this value should be replaced by a user-determined character. I've got no idea how to do this, I have the code to generate a 10x10 table which is below, I appreciate any help!
public static void main(String[] args) {
int tableSize = 10;
printMultiplicationTable(tableSize);
}
public static void printMultiplicationTable(int tableSize) {
System.out.println("Please enter a letter");
Scanner sc = new Scanner(System.in);
char letter = sc.next().charAt(0);
System.out.println("Please enter a number");
Scanner sc1 = new Scanner(System.in);
int num = sc1.nextInt();
System.out.format(" ");
for(int i = 1; i<=tableSize;i++ ) {
System.out.format("%4d",i);
}
System.out.println();
System.out.println("-------------------------------------------"
+ "---");
for(int i = 1 ;i<=tableSize;i++) {
System.out.format("%4d |",i);
for(int j=1;j<=tableSize;j++) {
if(i*j > num) {
System.out.format("%4d",i*j);
}
else {
System.out.format("%4d",letter);
}
System.out.println();
}}}}
Aucun commentaire:
Enregistrer un commentaire