File tree Expand file tree Collapse file tree 4 files changed +54
-0
lines changed Expand file tree Collapse file tree 4 files changed +54
-0
lines changed Original file line number Diff line number Diff line change
1
+ import java .io .BufferedReader ;
2
+ import java .io .IOException ;
3
+ import java .io .InputStreamReader ;
4
+
5
+ public class Main {
6
+ public static void main (String [] args ) throws IOException {
7
+ // constructing a BufferedReader obj
8
+ BufferedReader reader = new BufferedReader (new InputStreamReader (System .in ));
9
+
10
+ System .out .print ("Enter a string: " );
11
+ String str = reader .readLine ();
12
+
13
+ System .out .println ("You entered: " );
14
+ System .out .println ("\t " +str );
15
+ }
16
+
17
+ }
Original file line number Diff line number Diff line change
1
+ public class Main {
2
+ public static void main (String [] args ) {
3
+ // no constructor is needed
4
+
5
+ System .out .print ("Enter your string: " );
6
+ String str = System .console ().readLine ();
7
+
8
+ System .out .println ("You entered: " );
9
+ System .out .println ("\t " +str );
10
+
11
+ }
12
+ }
Original file line number Diff line number Diff line change
1
+ import java .util .Scanner ;
2
+
3
+ public class Main {
4
+ public static void main (String [] args ) {
5
+ // constructing a Scanner class obj
6
+ Scanner scan = new Scanner (System .in );
7
+
8
+ System .out .print ("Enter a string: " );
9
+ String str = scan .nextLine ();
10
+
11
+ System .out .println ("You entered: " );
12
+ System .out .println ("\t " +str );
13
+ }
14
+ }
Original file line number Diff line number Diff line change
1
+ // GUI
2
+ import javax .swing .JOptionPane ;
3
+
4
+ public class Main {
5
+ public static void main (String [] args ) {
6
+ // no constructor is needed
7
+
8
+ String str = JOptionPane .showInputDialog ("Enter a string:" );
9
+ JOptionPane .showMessageDialog (null , "You entered: " + str );
10
+ }
11
+ }
You can’t perform that action at this time.
0 commit comments