Computer Science, asked by mansuraahmed01, 1 month ago

Write a statement for each of the following: (3)

i)store a number 275 as a String.

ii)Convert the string to a numeric value.

iii) Add it to the existing total of 1000 to update the total.​

Answers

Answered by BrainlyProgrammer
1

Answer:

(i)  \texttt{String s="275";}

_____

(ii)  \texttt{int p=Integer.parseInt(s);} \\  \tt \: or \\  \texttt{int p=Integer.valueOf(s);}

_____

(iii)  \texttt{int total = 1000;} \\  \texttt{total  = total + p;}

Remember:-

  • Integer.toString() converts integer to string.
  • Integer.parseInt() or Integer.valueOf() converts String to integer.
  • It must be kept in mind that the string should not contain any alphanumeric characters otherwise it will throw NumberFormatException
Similar questions