Hola buenas, resulta que tengo que realizar un programa en Java por consola, lance un hilo que imprima la tabla de multiplicar de ese número.
Alguna idea? Gracias!
Si bien entendí. sería algo así:
package test;
import java.util.Scanner;
public class Test extends Thread {
public static void main(String[] args) {
System.out.print("Numero: ");
int num = new Scanner(System.in).nextInt(); // recibimos el numero por input
new Thread(new Test(num)).start(); // creamos e iniciamos el hilo
}
private int num;
public Test(int num) {
this.num = num;
}
@Override
public void run() {
// sacamos toda la tabla de multiplicar del numero
System.out.println("1 * " + this.num + " = " + 1 * this.num);
System.out.println("2 * " + this.num + " = " + 2 * this.num);
System.out.println("3 * " + this.num + " = " + 3 * this.num);
System.out.println("4 * " + this.num + " = " + 4 * this.num);
System.out.println("5 * " + this.num + " = " + 5 * this.num);
System.out.println("6 * " + this.num + " = " + 6 * this.num);
System.out.println("7 * " + this.num + " = " + 7 * this.num);
System.out.println("8 * " + this.num + " = " + 8 * this.num);
System.out.println("9 * " + this.num + " = " + 9 * this.num);
System.out.println("10 * " + this.num + " = " + 10 * this.num);
}
}
Ejemplo de Output con el número 5:
Numero: 5
1 * 5 = 5
2 * 5 = 10
3 * 5 = 15
4 * 5 = 20
5 * 5 = 25
6 * 5 = 30
7 * 5 = 35
8 * 5 = 40
9 * 5 = 45
10 * 5 = 50
Si, exacto !! Es justamente eso! Muchas gracias, me has servido de mucha ayuda! No lograba entender cómo hacerlo.