+ 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."); } } }
16 Réponses
+ 25
@Uday Krishna I will try to use the BufferReader :) thank you for your help 💜
+ 17
I think I can't get any user input in this way
by using sololearn
+ 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.
+ 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
+ 3
Use BufferedReader age = new BufferedReader(new InputStreamReader(System.in));
+ 3
See my codes I am uploading a code for your question
+ 3
Jasmine you're near by face look to my girl that leaves me 😞😞😞can I be your friend? 😞
+ 2
Jasmin use scanner for input
+ 2
I think your program is about telling eligible if age >18
+ 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
+ 2
and Scanner is easy and better from buffer reader as buffer reader takes 4byte and scanner take a much more than that
+ 1
BufferReader takes lesser time
+ 1
Swing/AWT/FX are not supported by playground, showInputDialog must be replaced for Scanner
+ 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();
+ 1
by using Scanner, a lot of processing time is saved.
0
hello. my name is hadi. i love to learn c#. do you have help me?