Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

305
Views
¿Cómo hacer un programa multiplicador en Java usando la línea de entrada?

Traté de resolver un problema en CodeChef. El problema debería ser multiplicar dos números. Este es el guión:

 import java.util.*; import java.lang.*; class Main { public static void main (String[] args) throws java.lang.Exception { int test; Scanner sc = new Scanner(System.in); test = sc.nextInt(); while(test!=0){ test = test - 1; int nummer1; int nummer2; nummer1 = sc.nextInt(); nummer2 = sc.nextInt(); int nummer3; nummer3 = nummer1 * nummer2; System.out.println(nummer3); } } }

Lo que mi programa necesita hacer es: primero, obtener la cantidad de casos de prueba, y luego, debe multiplicar nummer1 y nummer2 para formar nummer3 . Por ejemplo: ENTRADA

 2 2 3 4 6

Y la SALIDA:

 6 24

Pero todo el programa me está dando un error de tiempo de ejecución (NZEC). ¿Qué estoy haciendo mal? Me da este error:

 Exception in thread "main" java.util.NoSuchElementException at java.util.Scanner.throwFor(Scanner.java:862) at java.util.Scanner.next(Scanner.java:1485) at java.util.Scanner.nextInt(Scanner.java:2117) at java.util.Scanner.nextInt(Scanner.java:2076) at Main.main(Main.java:10)
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Yo lo haría de esta manera:

 Scanner sc = new Scanner(System.in); int test = Integer.parseInt(sc.nextLine()); while (test-- > 0) { String[] tmp = sc.nextLine().split("\\s+"); int result = Integer.parseInt(tmp[0]) * Integer.parseInt(tmp[1]); System.out.println(result); } sc.close();
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!