Solved

Problem in execution

Posted on 1998-11-23
2
177 Views
Last Modified: 2010-03-30
Hello,

  Consider the following code.

import javlib.in.*;

class testforss1
{
            testforss1()
            {
                  prt.disp("ur in the base class");
            }
}
      
class testforss
{
            private testforss1[] t1 = new testforss1[10];
            private int x;

            testforss()
            {
                  System.out.println("Its okay");
            }
            Random rand = new Random();
            int x1 = rand.nextInt();
            
            System.out.println("The output is " + (int)x1);
            public static void main(String[] args)
            {
                        testforss[] t = new testforss[1];
                        System.out.println("The length is " + t.length);
            }
}

I am just trying to print the variable x1 when i compile this code it is saying the following error

C:\SSLIB\testforss.java:23: Type expected.
            System.out.println("The output is " + (int)x1);
                               ^
1 error
Finished

What might be the error??

regards
Nature
0
Comment
Question by:nature
2 Comments
 
LVL 16

Accepted Solution

by:
heyhey_ earned 20 total points
ID: 1228036

in the object definition you can have
-) field definitions (that is  Random rand = new Random(); )
-) method definitions (that is public void main(String[] args) {})
but not random pieces of code.

the error that you receive

>> C:\SSLIB\testforss.java:23: Type expected.
>> System.out.println("The output is " + (int)x1);

means that comiler is expecting another field or method definition, not a code ...

so - you must put this code in your constructor or some other method ...

hope this helps
  heyhey

0
 

Author Comment

by:nature
ID: 1228037
Yep it works thanks

nature
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
triangle challenge 4 77
network + 7 73
backtracking recursion  code 19 40
Java Timer (static) 9 12
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now