id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

amjadm@miamioh.edu assignmentiii > switchSigns
prev  |  next  |  chance

Given a string of int numbers separated by space, switch the negative numbers to positive and vice versa, and return a new string.
Hint: Since you don't know the length of the given string, loop though the string, and every time you should look for the index of the space (using indexOf() method from string class) because that tells you where the next number ends. Now by knowing where a number starts and ends you can use substring to read that number, and you can convert that string into an actual number using Integer.parseInt() method. If the number is positive, add a negative number to the result string, otherwise add a negative number to the result string.


switchSigns("") → ""
switchSigns("1") → "-1"
switchSigns("-2 3") → "2 -3"

...Save, Compile, Run (ctrl-enter)

public String switchSigns(String str) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Post-solution available

Copyright Nick Parlante 2017 - privacy