Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 24th, 2013, 10:08 AM
kungfupanda kungfupanda is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 1 kungfupanda User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 26 m 16 sec
Reputation Power: 0
Optimize this code

import java.util.*;
import java.math.*;
class M
{

public static void main(String args[])
{
final int size=3;
Scanner s=new Scanner(System.in);
int a1[]=new int[size];
int a2[]=new int[size];
int i,num1,num2,sum;
i=0;
num1=0;
num2=0;
sum=0;
System.out.println("Enter elements for 1st array \n");
for(i=0;i<size;++i)
a1[i]=s.nextInt(); // scanf("%d",&a1[i]);
System.out.println("Enter elements for 2nd array \n");
for(i=0;i<size;++i)
a2[i]=s.nextInt(); // scanf("%d",&a2[i]);
num1 = convert(a1);
num2 = convert(a2);
sum = num1 + num2;
System.out.println("Sum of arrary \n"+sum);
}
static int convert(int arr[])
{
int i =0, num=0;
final int size=3;
try{
for(i = 0;;++i)
{
num += arr[i] * Math.pow(10,i);
System.out.println("Sum of array a[size] \n"+(int)Math.pow(10,i)+""+arr[i]);
}

}catch(Exception e){}
return num;
}
}
somebody optimize this code right now it is taking 246mb

Reply With Quote
  #2  
Old January 24th, 2013, 11:33 AM
salem's Avatar
salem salem is offline
Contributed User
Click here for more information
 
Join Date: Jun 2005
Posts: 3,840 salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 153 Folding Title: Novice Folder
Time spent in forums: 2 Months 3 Weeks 2 Days 21 h 15 m 20 sec
Reputation Power: 1774
> somebody optimize this code right now it is taking 246mb
Which real operating system are you using?
Which JavaVM are you using?
How did you arrive at 246Mb?

For me, your program uses about 15Mb (it uses 14Mb on just "hello world")
$ java -version
java version "1.6.0_24"
OpenJDK Runtime Environment (IcedTea6 1.11.5) (6b24-1.11.5-0ubuntu1~11.10.1)
OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Optimize this code

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap