Java Problem

Associate
Joined
8 Jan 2009
Posts
1,492
Location
Northern Ireland
This piece I wrote here comes up with errors to the InOut.print etc. I use Eclipse, and I have also used Net Beans 6.7.1, I have tried to use System.out, but again when I go to compile, I get errors with System.out. Anybody any ideas. Thanks

public class Welcome3{
// no comments
public static void main(String args[]){
InOut.print ("Welcome to");
// note only a print
InOut.println("the University of Ulster.");
InOut.println();
InOut.print("This is used ");
//note space after the word used (previous line)
InOut.println("to show the impact");
InOut.println();
InOut.println("of a println statement.");

}//main
}//Welcome3
 
What error are you getting? i would have just used System.out.println myself
Code:
public class welcome{
// no comments

public static void main(String args[]){
System.out.println ("Welcome to");
// note only a print
System.out.println("the University of Ulster.");
System.out.println();
System.out.println("This is used ");
//note space after the word used (previous line)
System.out.println("to show the impact");
System.out.println();
System.out.println("of a println statement.");

}//main
}//Welcome3

compiles and runs fine for me
 
Last edited:
Thanks Dazzy G, The System.out. println statement worked. Cant understand why it did not work the first time. However, that InOut.println statement was getting me a red line under it saying there was a error, and refused to compile. Last one. But im getting this now.
public class Add2Integers{

public static void main(String args[]){


int number1, number2, total; // Declaring 3 int variables

System.out.print("Please, enter your first number: ");
number1=System.out.readInt();

System.out.print("Please enter your second number: ");
number2=System.out.readInt();

total=number1+number2;
System.out.print("Total of the numbers" +number1 +""+number2);
System.out.println(" is " +total);

}//main

}//Add2Integers

With the error message being,
java.lang.Error: Unresolved compilation problems:
The method readInt() is undefined for the type PrintStream
The method readInt() is undefined for the type PrintStream

at Add2Integers.main(Add2Integers.java:22)
Exception in thread "main"
 
Last edited:
Have your university included a java file for you? You might need to use that to get the 'InOut.print' function to work.

For our first couple of assignments we were given a class called 'EasyWriter' to include, which provided us with an 'easy' way to output to the console. It was a bit retarded, yes, but your university might have done something similar.
 
you want to read things in, .out is an output stream, .in is the input stream.

have a look at the api http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html

edit:
Have your university included a java file for you? You might need to use that to get the 'InOut.print' function to work.

For our first couple of assignments we were given a class called 'EasyWriter' to include, which provided us with an 'easy' way to output to the console. It was a bit retarded, yes, but your university might have done something similar.
That sounds like what they've done, the methods you are trying to call arn't standard ones
 
Last edited:
That sounds like what they've done, the methods you are trying to call arn't standard ones

I would agree with you on that, which means, in the outside world i will have to learn some of it over again. Its like this one here, where the readInt statements will be wrong,

public class Swapintegers{

public static void main(String args[]){

int first,second,temp;

System.out.print("Enter an integer value: ");
first = System.in.readInt();


System.out.print("Enter an integer value: ");
second = System.in.readInt();


System.out.println("Prior to swapping .....");
System.out.println();
System.out.println("First number="+first);
System.out.println("Second number="+second);
System.out.println();

// Swap the numbers around
// NB requires the use of a third variable-temp. WHY?

temp=first;
temp=second;
second=temp;

//now repeat the message EXACTly as before

System.out.println("After Swapping .......");
System.out.println();
System.out.println("First number = " + first);
System.out.println("Second number = " + second);

System.out.println();



}//main


}//Swapintegers
 
Last edited:
Back
Top Bottom