Syvum Home Page

Home > Discussions > For all activities

Discussion topic: Contributed Answer/Explanation to Q. 12

Viewing replies        View entire discussion

To go to the homepage of this topic, click here.
Home: angel118Original MessageReply  
Subject: Contributed Answer/Explanation to Q. 31
   import java.io.*;

Posted at: Thu Dec 16 15:40:02 2010 (GMT)

Page 1 of 1
From: angel118Reply 1 of 2Reply
Subject: Contributed Answer/Explanation to Q. 31
   the code is written in the explanation
   <p><span style="white-space: pre" class="Apple-tab-span">import
   java.io.*;</span></p><p>class
   SumOfNumbers</p><p>public static void main(String
   args[])</p><p>throws
   IOException</p><p>{</p><p><span
   style="white-space: pre" class="Apple-tab-span">	    
   </span>BufferedReader br=new BufferedReader(new
   InputStreamReader(System.in));</p><p><span
   style="white-space: pre" class="Apple-tab-span">	   </span>int
   num;</p><p><span style="white-space: pre"
   class="Apple-tab-span">	 </span>double
   sumNegative=0,sumPosEven=0,sumPosOdd=0;</p><p><span
   style="white-space: pre" class="Apple-tab-span">	   
   </span>do</p><p><span style="white-space: pre"
   class="Apple-tab-span">  </span>{</p><p><span
   style="white-space: pre" class="Apple-tab-span">		
   </span>System.out.println("Enter  the number:
   ");</p><p><span style="white-space: pre"
   class="Apple-tab-span">		   
   </span>num=Integer.parseInt(br.readLine());</p><p><span
   style="white-space: pre" class="Apple-tab-span">		     
   </span>if(num<0)</p><p><span style="white-space:
   pre" class="Apple-tab-span">			 
   </span>sumNegative+=num;</p><p><span
   style="white-space: pre" class="Apple-tab-span">		
   </span>else if(num%2==0  &&
   num>0)</p><p><span style="white-space: pre"
   class="Apple-tab-span">			 
   </span>SumPosEven+=num;</p><p><span style="white-space:
   pre" class="Apple-tab-span">	     
   </span>else</p><p><span style="white-space: pre"
   class="Apple-tab-span">			    
   </span>sumPosOdd+=num;</p><p>}while(num!=0);</p><
   p>System.out.println("Sum of negative integers:
   "+sumNegative);</p><p> </p><p
   style="margin-top: 0px; margin-bottom: 2px">System.out.println("Sum
   of positive even integers: "+sumPosEven);</p><div><p
   style="margin-top: 0px; margin-bottom: 2px">System.out.println("Sum
   of positive odd integers:
   "+sumPosOdd);</p></div><div>}</div><div>}
    </div>

Posted at: Thu Dec 16 15:45:09 2010 (GMT)

From: angel118Reply 2 of 2Reply
Subject: Contributed Answer/Explanation to Q. 31
   the code is written in the explanation
   <p><span style="white-space: pre" class="Apple-tab-span">import
   java.io.*;</span></p><p>class
   SumOfNumbers</p><p>{ </p><p>public static void
   main(String args[])</p><p>throws
   IOException</p><p>{</p><p><span
   style="white-space: pre" class="Apple-tab-span">
   </span>BufferedReader br=new BufferedReader(new
   InputStreamReader(System.in));</p><p><span
   style="white-space: pre" class="Apple-tab-span">	   </span>int
   num;</p><p><span style="white-space: pre"
   class="Apple-tab-span">	 </span>double
   sumNegative=0,sumPosEven=0,sumPosOdd=0;</p><p><span
   style="white-space: pre" class="Apple-tab-span">	   
   </span>do</p><p><span style="white-space: pre"
   class="Apple-tab-span">  </span>{</p><p><span
   style="white-space: pre" class="Apple-tab-span">		
   </span>System.out.println("Enter  the number:
   ");</p><p><span style="white-space: pre"
   class="Apple-tab-span">		   
   </span>num=Integer.parseInt(br.readLine());</p><p><span
   style="white-space: pre" class="Apple-tab-span">		     
   </span>if(num<0)</p><p><span style="white-space:
   pre" class="Apple-tab-span">			 
   </span>sumNegative+=num;</p><p><span
   style="white-space: pre" class="Apple-tab-span">		
   </span>else if(num%2==0  &&
   num>0)</p><p><span style="white-space: pre"
   class="Apple-tab-span">			 
   </span>SumPosEven+=num;</p><p><span style="white-space:
   pre" class="Apple-tab-span">	     
   </span>else</p><p><span style="white-space: pre"
   class="Apple-tab-span">			    
   </span>sumPosOdd+=num;</p><p>}while(num!=0);</p><
   p>System.out.println("Sum of negative integers:
   "+sumNegative);</p><p style="margin-top: 0px; margin-bottom:
   2px">System.out.println("Sum of positive even integers:
   "+sumPosEven);</p><div><p style="margin-top: 0px;
   margin-bottom: 2px">System.out.println("Sum of positive odd
   integers:
   "+sumPosOdd);</p></div><div>}</div><div>}
    </div> 

Posted at: Thu Dec 16 15:45:35 2010 (GMT)

Page 1 of 1

To post to this forum, you must be signed in as a Syvum member. Please sign in / register as a member.

Contact Info © 1999-2024 Syvum Technologies Inc. Privacy Policy Disclaimer and Copyright