Biggest Calculater in the world :3 -_- ye koi sadharan - TopicsExpress



          

Biggest Calculater in the world :3 -_- ye koi sadharan calculater nahi hai :v //! Calc.java //! package calc; /** Author Vikas Yadav At Google Inc. */ import java.util.Scanner; public class Calc{ public static void main(String... arg){ if(arg.length != 2){ System.out.println(Please use connect syntex : Program ); return; } String numA = arg[0];//; String numB = arg[1]; System.out.println(\n\n\nBiggest summer in the world ! Tiger R-3 ); /* System.out.println(Biggest Calculater in the world ! By Google Inc.\n\n); Scanner scr = new Scanner(System.in); System.out.println(); System.out.println(Enter the first Number : ); numA = scr.nextLine(); System.out.println(\n\nEnter the first Number : ); numB = scr.nextLine(); //System.out.println(Input numbers are : + numA + and + numB); */ if(checkInput(numA,numB)){ // System.out.println(Everythig seems fine !); System.out.println(\n\n\n + sum(numA, numB)); }else{ System.out.println(\n\nPlease enter the Numbers only !); } System.out.println(\n\nGood luck and happy coding !); } public static boolean checkInput(String numA, String numB){ boolean a = true; boolean b = true; //System.out.println(Checking ..); for(int i = 0; i < numA.length(); i++){ if( !(Character.isDigit(numA.charAt(i))) ){ // System.out.println(Sorry it also contain the chars ..); a = false; break; } } // first checking ends for(int i = 0; i < numB.length() && a; i++){ if( !(Character.isDigit(numB.charAt(i))) ){ // System.out.println(Sorry it also contain the chars ..); b = false; break; } } // seconds checking ends if(a && b) return true; return false; } // end check input public static String sum(String firstNum, String secondNum){ int arrf[] = null; int arrs[] = null; char big = a; if(firstNum.length() > secondNum.length()){ arrf = new int[firstNum.length()]; arrs = new int[firstNum.length()]; big = a; }else{ arrf = new int[secondNum.length()]; arrs = new int[secondNum.length()]; big = b; } if(firstNum.length() == secondNum.length()) big = c; // now we are gonna to assign values // System.out.println(Array size : a + arrf.length + string a + firstNum.length() + b : + arrs.length + string + secondNum.length()); if(big == a){ for(int i = arrf.length - 1; i >= 0 ; i--){ arrf[i] = Integer.parseInt(firstNum.substring(i,i+1)); } for(int i = (arrs.length - 1); i >= (arrs.length - secondNum.length()) ; i--){ int j = i - (arrs.length - secondNum.length()); arrs[i] = Integer.parseInt(secondNum.substring(j,j+1)); } } if(big == b){ for(int i = arrs.length - 1; i >= 0 ; i--){ arrs[i] = Integer.parseInt(secondNum.substring(i,i+1)); } for(int i = (arrf.length - 1); i >= (arrf.length - firstNum.length()) ; i--){ int j = i - (arrf.length - firstNum.length()); arrf[i] = Integer.parseInt(firstNum.substring(j,j+1)); } } if(big == c){ for(int i = (arrf.length - 1); i >= 0 ; i--){ arrf[i] = Integer.parseInt(firstNum.substring(i,i+1)); arrs[i] = Integer.parseInt(secondNum.substring(i,i+1)); } } /** It was for testing purpuse for(int i = 0 ; i < arrf.length; i ++){ System.out.println(arrf[i] + : + arrs[i]); } */ int carry = 0; String ans = ; for(int i = (arrf.length - 1); i >= 0; i --){ if((arrf[i] + arrs[i] + carry) >= 10 ){ Integer inte = new Integer( ( arrf[i] + arrs[i] + carry ) % 10 ); ans = inte.toString() + ans; carry = 1; }else{ Integer inte = new Integer( ( arrf[i] + arrs[i] + carry ) ); ans = inte.toString() + ans; carry = 0; } } if(carry != 0) ans = carry + ans; //System.out.println(Answer is : + ans); return ans; } // end sum method } //:~
Posted on: Sun, 31 Aug 2014 17:59:23 +0000

Trending Topics



Recently Viewed Topics




© 2015