Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(Edited) Re-design and re-implement program Practice_6_2 (name it EvenOdd) such

ID: 3587269 • Letter: #

Question

(Edited)

Re-design and re-implement program Practice_6_2 (name it EvenOdd) such that only one while loop is used to determine all even and odd numbers between 50 and 100. Again, printed all even numbers on a single line, separated by commas, and all odd numbers on a new line, separated by commas. Use proper labels for the output. Use escape character to lineup the outputs after the labels as shown below.

Even numbers between 50 and 100: 50, 52, 54, 56, 58, 60, 62, 64, …

Odd numbers between 50 and 100: 51, 53, 55, 57, 59, 61, 63, 65, …  

(Pevious) Write a Java program Practice _6_4 to read a string value from the user, the program prints out the entered string, and then prints out the string one character per line. Use proper labels for the outputs as shown in the example below.

Entered String: Test Input.

Character #1: T

Character #2: e

Character #3: s

Character #4: t

Character #5:

Character #6: I

Character #7: n

Character #8: p

Character #9: u

Character #10: t

Character #11: .

Explanation / Answer

WhileLoopEvenOddNos.java

public class WhileLoopEvenOddNos {

public static void main(String[] args) {

int start = 50;
int stop = 100;
int flag = 0;
System.out.print("Even numbers between 50 and 100:");
while (true) {

if (flag == 0) {
if (start <= stop) {

if (start % 2 == 0) {
System.out.print(start);
if (start != stop) {
System.out.print(",");

} else {
System.out
.print(" Odd numbers between 50 and 100:");
stop = 50;
flag = 1;

}

}

start++;
continue;

}

} else {

if (stop < start) {

if (stop % 2 != 0) {
System.out.print(stop);
if (stop != start - 2) {
System.out.print(",");
} else {
break;
}

}
stop++;

}

}

}
}

}

_________________

Chapter.java

import java.util.Scanner;

public class Chapter {

public static void main(String[] args) {
// Declaring variables
String str;

/*
* Creating an Scanner class object which is used to get the inputs
* entered by the user
*/
Scanner sc = new Scanner(System.in);

// Getting the input entered by the user
System.out.print("Enter String :");
str = sc.nextLine();

System.out.println("Entered String :" + str);
for (int i = 0; i < str.length(); i++) {
System.out.println("Character #" + (i + 1) + ":" + str.charAt(i));

}

// Displaying the output

}

}

________________

Output:

Enter String :Test Input.
Entered String :Test Input.
Character #1:T
Character #2:e
Character #3:s
Character #4:t
Character #5:
Character #6:I
Character #7:n
Character #8:p
Character #9:u
Character #10:t
Character #11:.

_________________Thank YOu