• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

laying out Java environment

 
Greenhorn
Posts: 3
Mac OS X
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 75
Android Chrome Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The nextInt() method usually implies a Scanner class.

Read this Scanner, it'll tell you how to use it.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for help y'all. I'm re downloading eclipse as we speak and well see how that goes.
 
Marshal
Posts: 79177
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic