The same code doesn't work in the phone!!! | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 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?

1st Jan 2018, 8:48 PM
Yunus
7 ответов
+ 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 :)
2nd Jan 2018, 12:56 AM
Duncan
Duncan - avatar
+ 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.
1st Jan 2018, 10:07 PM
UnknownYmous
+ 8
@Yunus, please post the code here so we can help
1st Jan 2018, 10:09 PM
David Akhihiero
David Akhihiero - avatar
+ 6
Thank you very much guys, my code worked thanks to "Duncan" :)
2nd Jan 2018, 5:02 AM
Yunus
+ 4
------java.util.noSuchElementException:No Line Found----- Error is almost like that
1st Jan 2018, 9:08 PM
Yunus
+ 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; } }
1st Jan 2018, 10:20 PM
Yunus
+ 2
What error did you get?
1st Jan 2018, 9:06 PM
Sad
Sad - avatar