+ 6
The same code doesn't work in the phone!!!
I wrote a code on my laptop and it was working but when I checked it on the phone, it gave me an error. Could you please help me with this?
7 Respuestas
+ 7
Hey Yunus
You have a space in line 24, in this bit ( System.in). Remove the space and it works :) Can't explain why, but would guess that Code Playground via the App has read in the space whereas via the Web is has not.
Scanner newScan = new Scanner(System.in); // variable 'newScan' is now an instance of a Scanner
And just a tip, if you make your code public, you can paste a link directly to your code in the Q&A section :)
+ 17
if you run the code online or offline in phone it does not run as good as you run in laptop because java needs an environment which would have in your laptop.
+ 8
@Yunus, please post the code here so we can help
+ 6
Thank you very much guys, my code worked thanks to "Duncan" :)
+ 4
------java.util.noSuchElementException:No Line Found----- Error is almost like that
+ 4
It is my code below.
-------------------------------
import java.util.Scanner;
/**
* __This program will do some method examples___
* @author __Yunus
*/
public class Lab06
{
public static void main( String[] args)
{
Scanner scan = new Scanner( System.in);
// constants
final String SEPARATOR = "----------------------------------------------------";
final int TERM_NUMBER = 10;
// variables
String beforeRevised;
String afterRevised;
// program code
beforeRevised = scan.nextLine();
System.out.println( "Revised string : " + reverse( beforeRevised ) );
System.out.println( SEPARATOR );
}
/**
* This method will reverse strings
* @param s is the string
* @return result which is reverse of 's' string
*/
public static String reverse (String s)
{
// variables
String realResult;
String result;
realResult = "";
result = "";
// for loop
for (int x = s.length(); x > 0; x--)
{
// seperating words from each other
if (s.charAt(x-1) == ' ')
{
realResult = result + " " + realResult;
result = "";
}
else
result = result + s.charAt(x-1);
}
// adding the last word to the realResult
realResult = result + " " + realResult;
return realResult;
}
}
+ 2
What error did you get?