+ 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); } }
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...
+ 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 .
+ 1
I am trying to use Scanner........
+ 1
Thank you so much.
+ 1
Thanks
+ 1
https://code.sololearn.com/c8dDnQ37N8k8/?ref=app CHECK THIS OUT
0
So, I am noob in Java. I started learning it yesterday.
0
You're welcome..
0
š
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. š