Friday, August 24, 2018

How to convert string into int primitive data type?


 package com.altafjava.test;  
 public class Test {  
     public static void main(String[] args) {  
         String s="526";  
         int sum=0;  
         for(int i=0;i<s.length();i++){  
             sum=(sum*10)+(s.charAt(i)-48);  
         }  
         System.out.println("Original string = "+s);  
         System.out.println("Converted integer = "+sum);  
     }  
 }  



How to convert string into int primitive data type?



Share this

0 Comment to "How to convert string into int primitive data type?"

Post a Comment