There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
acer black screen blue screen boot bsod computer connection crash css dell display driver drivers email error excel explorer firefox firefox 3 hard drive internet internet explorer itunes laptop lcd linux malware monitor network networking outlook outlook 2003 outlook express password printer problem ram router security slow software sound sprtcmd.exe trojan usb virus vista windows windows xp wireless
Software Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
Java Error Problem


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
ICONIC's Avatar
Computer Specs
Senior Member with 208 posts.
 
Join Date: Sep 2007
Experience: Intermediate
07-Nov-2007, 11:59 PM #1
Java Error Problem
// Program Name: rolladie.java
// Description: Showing the use of math.random();
//
// Author:
// Date:

import java.util.Arrays;

public class Tickets

{

public static void main (String[] args)

{

//Variables
final int BOARDS = 3;
final int DRAWS = 7;
final int LIMIT = 47;

//Logic
public int[][] board;

public int Ticket() {
init();
}

public int[][] getBoards() {
return board;
}

public int[] getMatches(int[] draft) {
int[] res = new int[BOARDS];
int[] sorted = draft;
Arrays.sort(sorted);


for (int i = 0; i < sorted.length; i++) {
for (int j = 0; j < BOARDS; j++) {
for (int k = 0; k < DRAWS; k++) {
if (sorted[i]==board[j][k]) {
res[j]++;
break;
}
}
}
}
return res;

}//end main\
}//end class



C:\Info1136code>javac Tickets.java
Tickets.java:23: illegal start of expression
public int[][] board;
^
1 error
__________________
People say they know a lot about themselves. I just know more about other things.
Chicon's Avatar
Computer Specs
Distinguished Member with 6,677 posts.
 
Join Date: Jul 2004
Location: 50° 34' 07.13" N - 04° 10' 23.
Experience: Second socks retriever
08-Nov-2007, 04:34 AM #2
In Java, all variables declared inside a method are members of that method. They are only 'alive' between the { } delimiters of the method. Therefore, the modifiers like public, private, ... are not applicable to them.
It's the reason why you have an illegal start of expression error.

Also, methods can't be nested within other methods; for example, the following coding is illegal :
Code:
 
public void aMethod() {
    ....
    public void anotherMethod() {
        ....
    } // end of anotherMethod
    ...
} // end of aMethod
__________________
Never teach an old monkey how to make faces. - (French maxim)
artur02's Avatar
Computer Specs
Member with 91 posts.
 
Join Date: Sep 2007
Location: Hungary
Experience: Advanced
08-Nov-2007, 04:35 AM #3
You are inside the main method, no need for public scope. If you want to make that public move to class level.

Code:
public class Tickets 
{
  ...
  public static void main (String[] args)
  {
    ...
    //Logic
    public int[][] board;
    ...
  }
  ...
}
Use:
Code:
public class Tickets 
{
  ...
  //Logic
  public int[][] board;
  
  public static void main (String[] args)
  {
    ...
  }
  ...
}
ICONIC's Avatar
Computer Specs
Senior Member with 208 posts.
 
Join Date: Sep 2007
Experience: Intermediate
08-Nov-2007, 09:10 AM #4
thanks i also have a problem with a similar program.


Heres the code that i have so far:


import java.util.*;

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

//declare variable
final int BOARDS = 3;
final int DRAWS = 7;
final int LIMIT = 47;

//title
System.out.println("Super 7 Lottery! ");
System.out.println("");

//Prompt User for Tickets to purchase
System.out.println("How many Tickets do you want to purchase?: ");
int numticket = input.nextInt();


//Generate all tickets


int rollValue = (int)(47*Math.random() + 1);


for (int i = 0; i < sorted.length; i++) {
for (int j = 0; j < BOARDS; j++) {
for (int k = 0; k < DRAWS; k++) {
if (sorted[i]==board[j][k]) {
res[j]++;
break;
}
}
}
}





}//ending main

}


Write a Java console program that will randomly generate the numbers for a Super 7 lottery ticket.

With each ticket the customer receives three sets of seven numbers. Each set of seven numbers is called a “board” in the lottery business. So, if the user buys just one ticket, they get 3 boards. If they buy two tickets, they get 6 boards. If they buy three tickets, they get 9 boards, and so on. Each number on a board is a unique integer (no duplicates permitted) in the range of 1 to 47 (inclusive).


Your program should do the following:
• Ask the user how many tickets they want to purchase. Remember, for one ticket you have to generate three rows of seven numbers.
• Generate all the tickets, ensuring no duplicate numbers within each board, and sort them in ascending order (smallest to largest).
• Output the numbers as displayed in the screen shots below:



that basically what i need to do


if anyone can help id really appreciate it.
__________________
People say they know a lot about themselves. I just know more about other things.
ICONIC's Avatar
Computer Specs
Senior Member with 208 posts.
 
Join Date: Sep 2007
Experience: Intermediate
08-Nov-2007, 01:23 PM #5
can anyone help please, im lost here
Chicon's Avatar
Computer Specs
Distinguished Member with 6,677 posts.
 
Join Date: Jul 2004
Location: 50° 34' 07.13" N - 04° 10' 23.
Experience: Second socks retriever
09-Nov-2007, 03:08 AM #6
In your previous thread, Big Favor Java Program, you're telling us you're a teacher in programming. Knowing that it may take a lot of time to prepare courses, I willingly built a whole program in order to relieve you.
In the present thread, you're showing you don't even know the basics of Java : you're copy pasting randomly pieces of my program without knowing how they work.
It can't work that way and it won't never work that way if you don't understand what you're doing.
I suggest you to practice with smallest programs to begin with in order to learn about the different Java utilities.
__________________
Never teach an old monkey how to make faces. - (French maxim)
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who help people like you solve computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 09:22 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.