Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

laying out Java environment

 
Alex Ss Smith
Greenhorn
Posts: 3
Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So the classic System.out.println("Hello Ranch"); ran without a problem but on code lines beyond that, for example age = nextInt(); , receive a "selection does not contain a main type" error. so i guess my question is what is the correct concise language to describe this issue and followed by what solution?
 
Aj Prieto
Ranch Hand
Posts: 75
Android Chrome Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The nextInt() method usually implies a Scanner class.

Read this Scanner, it'll tell you how to use it.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15272
37
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch, Alex.

Please show use your code, explain exactly what commands you are trying to run and what the error messages are that you get. The more precise you ask your question, the better people can help you and the quicker you'll solve the problem.
 
Alex Ss Smith
Greenhorn
Posts: 3
Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for help y'all. I'm re downloading eclipse as we speak and well see how that goes.
 
Campbell Ritchie
Sheriff
Posts: 48917
58
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alex Smith Smith wrote: . . . I'm re downloading eclipse as we speak and well see how that goes.
Beware: if you really are a beginner, using an IDE like Eclipse usually makes learning even more difficult than it already is.

If you are using Scanners, beware of a pitfall described here. You can also write yourself a utility class using Scanners which validates entry: start reading here.
 
Alex Ss Smith
Greenhorn
Posts: 3
Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so far..
import java.util.Scanner;
public class JavaTutorial2Math {
static void main(String[] args){
Scanner in = new Scanner(System.in);
int age;
System.out.println("How old are you?");
age = in.nextInt();
if (age >= 21)
System.out.println("You may enjoy a drink.");
else
System.out.println("You are not old enough to drink.");
}
}
and the program feeds me "selection does not contain a main type" unlike "Hello Ranch" so something with this scanner class causes this.
many thanks
 
Aj Prieto
Ranch Hand
Posts: 75
Android Chrome Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you're missing "public" on the second line, otherwise it won't run.

After adding that, the program runs fine for me.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic