+ 25

The output of this code is: time limit exceeded What does that mean ?

import javax.swing.JOptionPane; public class myAge { public static void main(String[] args) { String eingabe = JOptionPane.showInputDialog ( "Please enter your age:"); System.out.println(eingabe); int age = Integer.parseInt(eingabe); System.out.println(age); if (age < 18) { System.out.println("You are under age."); } else { System.out.println("You are an adult."); } } }

29th Dec 2016, 6:43 PM
Jasmin
Jasmin - avatar
16 Réponses
+ 25
@Uday Krishna I will try to use the BufferReader :) thank you for your help 💜
29th Dec 2016, 7:05 PM
Jasmin
Jasmin - avatar
+ 17
I think I can't get any user input in this way by using sololearn
29th Dec 2016, 6:54 PM
Jasmin
Jasmin - avatar
+ 4
The execution of your code took longer than the maximal execution time which sololearn has set, so the programm was exited. That most likely happens because the method you use for input isn't supported by sololearn or just takes too long. Use what Uday Krishna posted instead.
29th Dec 2016, 6:47 PM
LaserHydra
LaserHydra - avatar
+ 4
SoloLearn runs your Java program as a console application and since GUI runs on a event loop thread your program waits infinitely until the event loop gets a WM_QUIT message. Since the console doesn't know that a window has been created, it runs for a specific time interval and when it sees that the program's still running it shows TIME LIMIT EXCEEDED
2nd Jan 2017, 8:42 AM
Suvaditya
Suvaditya - avatar
+ 3
Use BufferedReader age = new BufferedReader(new InputStreamReader(System.in));
29th Dec 2016, 6:48 PM
Uday Krishna
Uday Krishna - avatar
+ 3
See my codes I am uploading a code for your question
4th Jan 2017, 4:47 PM
Bruh
+ 3
Jasmine you're near by face look to my girl that leaves me 😞😞😞can I be your friend? 😞
20th Jan 2017, 3:07 AM
Zohrab Alexanian
Zohrab Alexanian - avatar
+ 2
Jasmin use scanner for input
4th Jan 2017, 4:45 PM
Bruh
+ 2
I think your program is about telling eligible if age >18
4th Jan 2017, 4:47 PM
Bruh
+ 2
and Time Limit exceeded may mean that your code is stuck in an infinite loop or Sololearn's Compiler don't have such memory to handle that task or its on main thread and not proceeding
4th Jan 2017, 4:56 PM
Bruh
+ 2
and Scanner is easy and better from buffer reader as buffer reader takes 4byte and scanner take a much more than that
4th Jan 2017, 4:59 PM
Bruh
+ 1
BufferReader takes lesser time
29th Dec 2016, 6:49 PM
Uday Krishna
Uday Krishna - avatar
+ 1
Swing/AWT/FX are not supported by playground, showInputDialog must be replaced for Scanner
30th Dec 2016, 2:09 AM
BaHaMuT
BaHaMuT - avatar
+ 1
Try this: import javax.swing.*; ... String ageAsStrng = JOptionPane.showInputDialog( "Please enter your age:"); int age = Integer.parseInt(ageAsString); or this: import java.util.Scanner; ... Scanner input = new Scanner(System.in); int age = in.nextInt();
30th Dec 2016, 8:04 AM
Kamal Jassal
Kamal Jassal - avatar
+ 1
by using Scanner, a lot of processing time is saved.
21st Jun 2017, 8:00 AM
Das Man
Das Man - avatar
0
hello. my name is hadi. i love to learn c#. do you have help me?
13th May 2017, 9:23 AM
hadi