ajprincess
  • ajprincess
Please help:) write a java program that reads two integers as start and last. within that ranges, it should differentiate ODD values and EVEN values and display the separated list on screen with the sum of ODD and sum of EVEN. the program will be repeated until the termination condition is given by the user(Hint:if both start and last integer are equal then the program will terminate)
Computer Science
katieb
  • katieb
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Get this expert

answer on brainly

SEE EXPERT ANSWER

Get your free account and access expert answers to this
and thousands of other questions

ajprincess
  • ajprincess
This is vat I hav done so far. import java.io.*; public class Problem_a { public static void main(String[]args) throws IOException { BufferedReader keyboard=new BufferedReader (new InputStreamReader(System.in)); int a_1;//First term int a_n;//Last term int n;//Number of odd and even numbers available within the range int odd; int even; int sum_1=0;//Sum of odd numbers int sum_2=0;//sum of even numbers System.out.print("Enter the first number:"); a_1=Integer.parseInt(keyboard.readLine()); System.out.print("Enter the last number:"); a_n=Integer.parseInt(keyboard.readLine()); n=((a_n-a_1)/2)+1; if(((a_1%2==1) && (a_n%2==0)) || ((a_1%2==0) && (a_n%2==1))) { for(int i=1;i<=n;i++) { odd=a_1+((i-1)*2); System.out.print(" "+odd+" "); sum_1+=odd; } System.out.print("\n"); System.out.println(sum_1); for(int j=1;j<=n;j++) { even=(a_1+((j-1)*2))+1; System.out.print(" "+even+" "); sum_2+=even; } System.out.print("\n"); System.out.print(sum_2); } else if(a_1%2==1 && a_n%2==1) { for(int i=1;i<=n;i++) { odd=a_1+((i-1)*2); System.out.print(" "+odd+" "); sum_1+=odd; } System.out.print("\n"); System.out.println(sum_1); for(int j=1;j
ajprincess
  • ajprincess
@Chris2332 please help me:)
ajprincess
  • ajprincess
@eSpeX please help.

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

anonymous
  • anonymous
Sorry, computer stuff is out of my range of expertise.
ajprincess
  • ajprincess
That's k. Thanx a lot for taking a look.:)
experimentX
  • experimentX
what are you looking for? be concise ...
experimentX
  • experimentX
ah ... my bad. I don't have jdk installed ... hold on for few min.
ajprincess
  • ajprincess
oh k:)
experimentX
  • experimentX
I don't have fast connection ... perhaps it would take more than half hour ... can you summmarize what are you trying to do. I haven't programmed java for quite a long time.
ajprincess
  • ajprincess
I need to display the odd numbers and the even numbers between two numbers and also their sum seperately. When I compile the above program the output comes right. bt i have to include a condition that the program will be repeated until the termination condition is given by the user(Hint:if both start and last integer are equal then the program will terminate)
ajprincess
  • ajprincess
I hav no idea what that condition will be.
experimentX
  • experimentX
why not wrap the whole program in while loop?
experimentX
  • experimentX
or ... set the condition true ... inside while loop. use if start == final ... break; inside while loop.
experimentX
  • experimentX
hope this part is correct int sum_1=0;//Sum of odd numbers int sum_2=0;//sum of even numbers System.out.print("Enter the first number:"); a_1=Integer.parseInt(keyboard.readLine()); System.out.print("Enter the last number:"); a_n=Integer.parseInt(keyboard.readLine()); n=((a_n-a_1)/2)+1; if(((a_1%2==1) && (a_n%2==0)) || ((a_1%2==0) && (a_n%2==1))) { for(int i=1;i<=n;i++) { odd=a_1+((i-1)*2); System.out.print(" "+odd+" "); sum_1+=odd; } System.out.print("\n"); System.out.println(sum_1); for(int j=1;j<=n;j++) { even=(a_1+((j-1)*2))+1; System.out.print(" "+even+" "); sum_2+=even; } System.out.print("\n"); System.out.print(sum_2); } else if(a_1%2==1 && a_n%2==1) { for(int i=1;i<=n;i++) { odd=a_1+((i-1)*2); System.out.print(" "+odd+" "); sum_1+=odd; } System.out.print("\n"); System.out.println(sum_1); for(int j=1;j
experimentX
  • experimentX
while(true) { // first of all input the integers if start == final break; } rewrite that whole thing inside this loop.
experimentX
  • experimentX
gotta go out for a while ... brb in an hour.
ajprincess
  • ajprincess
ha k. Thanx a lot:)
ajprincess
  • ajprincess
import java.io.*; public class Problem_a { public static void main(String[]args) throws IOException { BufferedReader keyboard=new BufferedReader (new InputStreamReader(System.in)); int a_1;//First term int a_n;//Last term int n;//Number of odd and even numbers available within the range int odd; int even; int sum_1=0;//Sum of odd numbers int sum_2=0;//sum of even numbers while(true) { System.out.print("Enter the first number:"); a_1=Integer.parseInt(keyboard.readLine()); System.out.print("Enter the last number:"); a_n=Integer.parseInt(keyboard.readLine()); n=((a_n-a_1)/2)+1; if(((a_1%2==1) && (a_n%2==0)) || ((a_1%2==0) && (a_n%2==1))) { for(int i=1;i<=n;i++) { odd=a_1+((i-1)*2); System.out.print(" "+odd+" "); sum_1+=odd; } System.out.print("\n"); System.out.println(sum_1); for(int j=1;j<=n;j++) { even=(a_1+((j-1)*2))+1; System.out.print(" "+even+" "); sum_2+=even; } System.out.print("\n"); System.out.print(sum_2); } else if(a_1%2==1 && a_n%2==1) { for(int i=1;i<=n;i++) { odd=a_1+((i-1)*2); System.out.print(" "+odd+" "); sum_1+=odd; } System.out.print("\n"); System.out.println(sum_1); for(int j=1;j
experimentX
  • experimentX
seems it is working
experimentX
  • experimentX
put this thing right after you input it if (a_1 == a_n) { break; }
experimentX
  • experimentX
import java.io.*; public class Test { public static void main(String[]args) throws IOException { BufferedReader keyboard=new BufferedReader (new InputStreamReader(System.in)); int a_1;//First term int a_n;//Last term int n;//Number of odd and even numbers available within the range int odd; int even; int sum_1=0;//Sum of odd numbers int sum_2=0;//sum of even numbers while(true) { System.out.print("Enter the first number:"); a_1=Integer.parseInt(keyboard.readLine()); System.out.print("Enter the last number:"); a_n=Integer.parseInt(keyboard.readLine()); if (a_1 == a_n) { break; } n=((a_n-a_1)/2)+1; if(((a_1%2==1) && (a_n%2==0)) || ((a_1%2==0) && (a_n%2==1))) { for(int i=1;i<=n;i++) { odd=a_1+((i-1)*2); System.out.print(" "+odd+" "); sum_1+=odd; } System.out.print("\n"); System.out.println(sum_1); for(int j=1;j<=n;j++) { even=(a_1+((j-1)*2))+1; System.out.print(" "+even+" "); sum_2+=even; } System.out.print("\n"); System.out.print(sum_2); } else if(a_1%2==1 && a_n%2==1) { for(int i=1;i<=n;i++) { odd=a_1+((i-1)*2); System.out.print(" "+odd+" "); sum_1+=odd; } System.out.print("\n"); System.out.println(sum_1); for(int j=1;j
ajprincess
  • ajprincess
Ya it works perfectly nw:D. Thank u sooooooooooo much.:D That was a bigg help.

Looking for something else?

Not the answer you are looking for? Search for more explanations.