Solved

Problem in execution

Posted on 1998-11-23
2
180 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Android studio getdrawable(int) is deprecated 4 84
split53 challenge 7 96
nextBoolean(double p) for Random class 3 40
even odd program using while loop 3 40
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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 about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

770 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