All right, because I’m nice, I will write something for you that does exactly what you asked, no more. Then I will explain it.
This, by the way, runs exactly as written.
// All code copyright elfbabe, 2003.
// You need the Java io libraries to do stuff with input
import java.io.*;
// class culov = in a file called culov.java
public class culov {
// Main method. Program starts running here.
// Throws IOException means that if something messed up
// happens with the input/output, you're not doing anything.
// must say this, or compiler will complain
public static void main(String args) throws IOException{
// You're creating a BufferedReader called "in" that
// will read input from the console, System.in.
BufferedReader in = new BufferedReader
(new InputStreamReader(System.in));
// Display the stuff in quotes on the console
System.out.println("Please enter a number:");
// The user gets a blank line
// whatever they type is interpreted
// as an integer
int theInput =
Integer.parseInt(in.readLine());
// Display what’s in quotes
// Add theInput to the end
System.out.println("You entered " + theInput);
}
}
This will store whatever the user entered, number or not, as an Int. It’s dumb, though, so if the user enters something OTHER than an int, you’ll get a bunch of exceptions, and probably a crappy grade. At least I’d hope so. There are lots of ways of dealing with it, you can look them up. But this should get you started. If you want to store input as a String, it’s just String theInput = in.readLine();
Good luck.