everything seems so simple in java except the I/O stream. I have my program due in 2days and ive done everything but the I/O, people say it takes forever? so like whats the fastest and easiest way to input into a string or char? and whats the easiest way to output the same? like the basic and most simplest way ? Thanks...
C++ to Java
Page 1 of 17 Replies - 749 Views - Last Post: 11 August 2010 - 06:30 PM
Replies To: C++ to Java
#2
Re: C++ to Java
Posted 10 August 2010 - 03:41 PM
Scanner scan = new Scanner(System.in); for input
System.out.print(whatever}; is the equivalent of cout <<
System.out.print(whatever}; is the equivalent of cout <<
#3
Re: C++ to Java
Posted 10 August 2010 - 03:44 PM
How does this have anything to do with C++ to Java?
As for your question, the Scanner class is commonly used for input and to output in your console...you just use System.out.print()...
Note: you must import the Scanner class from java.util package
As for your question, the Scanner class is commonly used for input and to output in your console...you just use System.out.print()...
Scanner in = new Scanner(System.in);
String userInput = in.nextLine();
System.out.println("Your input was: " + userInput);
Note: you must import the Scanner class from java.util package
#4
Re: C++ to Java
Posted 10 August 2010 - 03:48 PM
oh coz iam from C++ and just switched to java.sry abt that... so i gotta do import java.util at the top? and thats it ? people talked about adding classes and classes to do this kinda stuff? whats that abt ?
PS: Garbage collection FTW
PS: Garbage collection FTW
bcranger, on 10 August 2010 - 02:44 PM, said:
How does this have anything to do with C++ to Java?
As for your question, the Scanner class is commonly used for input and to output in your console...you just use System.out.print()...
Note: you must import the Scanner class from java.util package
As for your question, the Scanner class is commonly used for input and to output in your console...you just use System.out.print()...
Scanner in = new Scanner(System.in);
String userInput = in.nextLine();
System.out.println("Your input was: " + userInput);
Note: you must import the Scanner class from java.util package
#5
Re: C++ to Java
Posted 10 August 2010 - 03:58 PM
// imports the entire util package... // * means ALL import java.util.*; // imports just the Scanner class from the util package import java.util.Scanner;
#6
Re: C++ to Java
Posted 10 August 2010 - 04:32 PM
#8
Re: C++ to Java
Posted 11 August 2010 - 06:30 PM
Hi, I believe you might want to read about the difference in System.out.println(), System.out.print(), etc. as each of them serve a different purpose and also something like:
nextInt() and nextDouble is used for different purpose.
Scanner sc = new Scanner(System.in); int temp = sc.nextInt(); double temp2 = sc.nextDouble();
nextInt() and nextDouble is used for different purpose.
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote



|