0

I need your help please .,java language

I want to reverse a char array And the word is given by the user. How can I read the char array from a user. https://code.sololearn.com/cZPrQL38O9Vj/?ref=app

25th Dec 2020, 4:09 PM
Amal Gil
Amal Gil - avatar
27 Réponses
+ 2
amal 01 use System.out.print(arr[i] ); for output the string without line break
25th Dec 2020, 5:10 PM
Hmd(inactive)
+ 5
import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String text = scanner.nextLine(); char[] arr = text.toCharArray(); for(int i=arr.length-1;i>=0;i--){ System.out.println(arr[i]); } }}
25th Dec 2020, 4:37 PM
Hmd(inactive)
+ 3
amal 01 show your try Attach your file here Add a MWE https://www.sololearn.com/post/75089/?ref=app
25th Dec 2020, 4:22 PM
Krish
Krish - avatar
+ 3
amal 01 Everything works but just a small improvement in the for loop for (int i = arr.length-1; i>=0; i--) { Sopln(arr[I]) ; } // you forgot this end bracket
25th Dec 2020, 4:34 PM
Krish
Krish - avatar
+ 3
in the condition of the loop you should: i>=0 also you forget this " } "
25th Dec 2020, 4:39 PM
Hmd(inactive)
+ 2
How you read charecters? As a string or individual chars? If later one, use a loop to read char by next().charAt(0) method of scanner object. Try and post that tried code of unsolved....
25th Dec 2020, 4:23 PM
Jayakrishna 🇮🇳
+ 2
amal 01 i already given about it in my 2nd post.. May you not noticed. System.out.println adds line break. While System.out.print() does not. And use i>=0 condition.
25th Dec 2020, 7:22 PM
Jayakrishna 🇮🇳
+ 2
Jayakrishna🇮🇳 Thank you so much . I did not noticed it.
25th Dec 2020, 10:03 PM
Amal Gil
Amal Gil - avatar
+ 2
Inside for loop use i >= 0 then. Resolved
26th Dec 2020, 6:51 PM
Manoj Soni
Manoj Soni - avatar
+ 2
amal 01 create a new question thread for your new question don't post all your questions in one post. This way you can get help.
28th Dec 2020, 11:18 AM
Krish
Krish - avatar
+ 2
amal 01 Strings are immutable (you cannot modify). String Buffer is mutable version of strings. You can modify original. It has already answered lot times so search bar will give more answers. Creating new will become dublicate. Use search bar. Hope it helps Edit : for more info : https://www.sololearn.com/discuss/724152/?ref=app https://www.sololearn.com/discuss/577260/?ref=app https://www.sololearn.com/discuss/141079/?ref=app https://www.sololearn.com/discuss/2117193/?ref=app https://www.sololearn.com/discuss/536275/?ref=app https://www.sololearn.com/discuss/93036/?ref=app https://www.sololearn.com/discuss/2100143/?ref=app
28th Dec 2020, 8:43 PM
Jayakrishna 🇮🇳
+ 1
amal 01 you forgot to add a link
25th Dec 2020, 4:29 PM
Krish
Krish - avatar
+ 1
amal 01 scanner.next().charAt(0); reads a single charecter. Ingores next charecters until spaee..
25th Dec 2020, 4:33 PM
Jayakrishna 🇮🇳
+ 1
Hasna The problem is that of I entered for example amal. The output should be lama. So need an array of characters starting from the lenght -1 .
25th Dec 2020, 5:04 PM
Amal Gil
Amal Gil - avatar
+ 1
hi amal 01 in your code: in line 11 read array until index 0 change i>0 to i>=0 in line 12 change println to print for a single line and line 13 close cicle for with }
26th Dec 2020, 1:05 AM
Ruben Enrique
Ruben Enrique - avatar
+ 1
Consider the Java program below, and then answer the questions that follow import java.util.Scanner; public class question2{ Public static void main(String [] args){ Scanner in = new Scanner(System.in); System.out.println(“Enter an Integer number”); int n = in.nextInt(); int s = 0, i = 1; do{ s + = Math.pow(i,2); i++; } while(i <=n); System.out.println(“Output = “+ s); } } Explain what the Java program is doing 5 marks Hence, give the Java class an appropriate name 2 marks If n = 5, what will be the output from the program (show your working) 8 marks Modify the program in 2(a) above to calculate S given that n S = ∑ i 3 i=i I need someone to help with the answer to this question please?
16th Jun 2021, 9:26 PM
Falola Micheal
Falola Micheal - avatar
0
Krish Here is my code try. I want to read a char array from the user but there isn't any way that I know.
25th Dec 2020, 4:28 PM
Amal Gil
Amal Gil - avatar
0
Jayakrishna🇮🇳 As an individuals chars Can I read char as a scanner object . How so.???
25th Dec 2020, 4:29 PM
Amal Gil
Amal Gil - avatar
0
Krish a link of what
25th Dec 2020, 4:30 PM
Amal Gil
Amal Gil - avatar
0
amal 01 It works but Edit to this for(int i=arr.length-1;i>=0;i--) //{ remove this brace. System.out.print(arr[i]); Condition use i>=0 And use System.out.print() method Edit : (to not put line break).
25th Dec 2020, 4:31 PM
Jayakrishna 🇮🇳