Advertisement
Droo

P4_1d

Oct 22nd, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.61 KB | None | 0 0
  1. package PreSession_05;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class p4_1d {
  6.  
  7.     public static void main(String[] args) {
  8.         // TODO Auto-generated method stub
  9.         int total=0;
  10.         Scanner sc = new Scanner(System.in);
  11.         System.out.println("Please input the begining value...");
  12.         int a=sc.nextInt();
  13.        
  14.         System.out.println("Please input the Ending Value...");
  15.         int b=sc.nextInt();
  16.        
  17.         do
  18.         {
  19.             if (a%2==1)
  20.             {
  21.                 System.out.println(a);
  22.                 total=total+a;
  23.                 a++;
  24.             }
  25.             else
  26.             {
  27.                 a++;
  28.             }
  29.            
  30.         }while (a<=b);
  31.        
  32.         System.out.println();
  33.         System.out.println("Total = "+total);
  34.  
  35.     }
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement