+ 1

Whats wrong with this Java code?

import java.util.Scanner; public class Program { public static void main(String[] args) { System.out.println ("Java is nice"); System.out.println ("My first Java code"); String myvar; Scanner myvar = New Scanner(System.in); System.out.println (myvar); } }

4th Apr 2022, 7:03 PM
Programmer
Programmer - avatar
10 Answers
+ 2
import java.util.Scanner; public class Program { public static void main(String[] args) { System.out.println ("Java is nice"); System.out.println ("My first Java code"); //String myvar; Scanner myvar = new Scanner(System.in); System.out.println(myvar.nextLine()); //myVar is an object now, use it's methods for reading inputs, like this : } } /* Now myvar is a Scanner object you created. Need Small n in new. Now through scanner object, you can read different types of input.. Like myvar.nextInt() for integer input. next() for a word to read. nextLine() to read entire line. nextDouble() for reading double value... Read again lesson "taking user input" . Hope it helps...
4th Apr 2022, 7:13 PM
Jayakrishna 🇮🇳
+ 1
What are you trying with this code? myVar is defined twice... try this : // String myvar; Scanner myvar = new Scanner(System.in); // small n, not New. System.out.println(myvar.nextLine()); //myVar is an object now, use it's methods for reading inputs, like this .
4th Apr 2022, 7:06 PM
Jayakrishna 🇮🇳
+ 1
I am trying to use Scanner........
4th Apr 2022, 7:07 PM
Programmer
Programmer - avatar
+ 1
Thank you so much.
4th Apr 2022, 7:09 PM
Programmer
Programmer - avatar
+ 1
Thanks
4th Apr 2022, 7:14 PM
Programmer
Programmer - avatar
5th Apr 2022, 9:47 AM
Divyanshu G
0
So, I am noob in Java. I started learning it yesterday.
4th Apr 2022, 7:07 PM
Programmer
Programmer - avatar
0
You're welcome..
4th Apr 2022, 7:15 PM
Jayakrishna 🇮🇳
0
😇
4th Apr 2022, 7:15 PM
Programmer
Programmer - avatar
0
First u have to create the object Scanner SC = new Scanner ( System.in) Then u can print the title. Hope u find it helpful. 😊
6th Apr 2022, 6:46 AM
Anushka Awasthi
Anushka Awasthi - avatar