Jump to content
SSForum.net is back!

Recommended Posts

Posted

I know there's an extremely simple answer to my question, and i'll probably kick myself once i figure it out.

 

I started looking into java again with xog's posting, and im trying to replicate his lotto program just as a warmup.

 

However, I CANNOT FOR THE LIFE OF ME, figure out what the most simple input request is.

 

I know its like this somehow:

public static void main(String[] args)
{
    ....
    System.out.print("Please type something here: ");
//I CANNOT FIGURE OUT WHAT GOES HERE. I THOUGHT IT WAS:
    String str = System.in.getString(); //or something along the lines of that. but i can't remember the exact syntax.
    ....
}

i am going to kick myself once i get the answer because i know it is so simple....

and yes, i've tried google for the last 30min... i dont want to use JOptionPane or any other GUI.

http://i157.photobucket.com/albums/t54/badgersocks/FHTG/FHTG%20-%20redone%20shizniz/tgmember11.png

rootbear75> here is me nude <spoiler tag: Pervert... how many of you actually clicked this?>

Samapico> I actually clicked the spoiler before reading what it was

Corey> I clicked it cause i read what sama said first.

darkreb0rn> I clicked it because I wanted to see you naked...

rootbear75> O.o __________________________________

2:IdleRPG> Mr Snuffleluphagus walked face-first into a tree. This terrible calamity has slowed them 0 days, 00:01:22 from level 18.

2:rootbear75> for fucks sake...

Posted
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
   public static void main(String[] args) {
       InputStreamReader isr = new InputStreamReader(System.in);
       BufferedReader input = new BufferedReader(isr);
       String inStr;
       System.out.println("Enter a string:");
       try {
         inStr = input.readLine();
         System.out.print("You entered ");
         System.out.println(inStr);
       }
       catch (IOException e) {
           System.out.println("Error");
       }
   }
}

Posted
i specifically remember a simple 1 line type of deal, that didn't require InputStream.

http://i157.photobucket.com/albums/t54/badgersocks/FHTG/FHTG%20-%20redone%20shizniz/tgmember11.png

rootbear75> here is me nude <spoiler tag: Pervert... how many of you actually clicked this?>

Samapico> I actually clicked the spoiler before reading what it was

Corey> I clicked it cause i read what sama said first.

darkreb0rn> I clicked it because I wanted to see you naked...

rootbear75> O.o __________________________________

2:IdleRPG> Mr Snuffleluphagus walked face-first into a tree. This terrible calamity has slowed them 0 days, 00:01:22 from level 18.

2:rootbear75> for fucks sake...

Posted (edited)

i specifically remember a simple 1 line type of deal, that didn't require InputStream.

import java.util.Scanner;

public class InputExp {

  public static void main(String[] args) {

      String name;
      int age;
      Scanner in = new Scanner(System.in);

      // Reads a single line from the console 
      // and stores into name variable
      name = in.nextLine();

      // Reads a integer from the console
      // and stores into age variable
      age=in.nextInt();
      in.close();            

      // Prints name and age to the console
      System.out.println("Name :"+name);
      System.out.println("Age :"+age);

   }
}

Something like that?

Source: http://www.java-tips.org/java-se-tips/java.util/how-to-read-input-from-console.html

 

 

Edit: I haven't really used scanner a lot. I normally use something like:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class ReadConsoleSystem {
 public static void main(String[] args) {

System.out.println("Enter something here : ");

try{
    BufferedReader bufferRead = new BufferedReader(new InputStreamReader(System.in));
    String s = bufferRead.readLine();

    System.out.println(s);
}
catch(IOException e)
{
	e.printStackTrace();
}

 }
}

Edited by BDwinsAlt
Posted

I think

...
String var = System.in.nextline();
...

Was what it was. Ill try it when I get home and let you know how it works...

I did think I have to import java.util.* but I don't remeber ever calling an instance of a Scanner object.

http://i157.photobucket.com/albums/t54/badgersocks/FHTG/FHTG%20-%20redone%20shizniz/tgmember11.png

rootbear75> here is me nude <spoiler tag: Pervert... how many of you actually clicked this?>

Samapico> I actually clicked the spoiler before reading what it was

Corey> I clicked it cause i read what sama said first.

darkreb0rn> I clicked it because I wanted to see you naked...

rootbear75> O.o __________________________________

2:IdleRPG> Mr Snuffleluphagus walked face-first into a tree. This terrible calamity has slowed them 0 days, 00:01:22 from level 18.

2:rootbear75> for fucks sake...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...