Solved

Problem in execution

Posted on 1998-11-23
2
182 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

688 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