Waiting for answer This question has not been answered yet. You can hire a professional tutor to get the answer.
Do not use any data structures. Do not use methods, basically write the code in the main () method. Do not write OOP.
Do not use any data structures. Do not use methods, basically write the code in the main () method.
Do not write OOP.
1.
Modify
the first program you have completed
a)
Prompt the user to input two distinct integers: n1 and n2.
b)
If the user enters the negative number(s), convert it/them to positive number(s).
c)
If n1 is greater than n2, swap them (make sure n1 is smaller than n2).
Then, use
two separate
do...while
loops
to do the following:
d)
Use a
do .. while
loop to output all the numbers divisible by 5 from n1 and n2 inclusive and the sum of
these numbers.
e)
Use a
do .. while
loop to output all the numbers not divisible by 5 from n1 and n2 inclusive and the
average of these numbers.
Then, use
two separate
for
loops
to do the following:
f)
Use a
for
loop to output all the odd numbers between n2 to n1 (large to small) inclusive.
g)
Use a
for
loop to output the table of each even integer and its square between 2 and 16 inclusive.
import java.util.Scanner;
public class Loop {
public static void main(String[] args) {
Scanner console = new Scanner(System.in);
//declare variable
int n1, n2, t,count,num1,num2, num3, num4;
double sum1, sum2;
System.out.println(" Enter 2 distinct integers");
System.out.println("Enter the first number: ");
n1 = console.nextInt();
System.out.println("Enter the second number: ");
n2 = console.nextInt();
if (n1 < 0)
n1 = -1 * n1;
if (n2 < 0)
n2 = -1 * n2;
if (n1 > n2)
{
t = n1;
n1 = n2;
n2 = t;
}
num1 = n1;
sum1 = 0;
System.out.print("Numbers divisible by 5 between "+n1+" and "+n2+" : ");
while(num1 <=n2)
{
if(num1 % 5==0)
{
System.out.print(num1 + " ");
sum1 = sum1 + num1;
}
num1++;
}
System.out.println();
System.out.println("Sum of these numbers : "+sum1);
num2 = n1;
sum2 = 0;
count =0;
System.out.print("Numbers not divisible by 5 between "+n2+" : ");
while(num2 <= n2)
{
if(num2 % 5!=0)
{
System.out.print(num2 + " ");
sum2 = sum2 + num2;
count++;
}
num2++;
}
System.out.println();
System.out.println("Average of these numbers : "+(sum2/count));
num3 = n2;
System.out.print("Odd numbers between 25 and 4 (large to small )");
while(num3 >= n1)
{
if(! (num3 % 2==0))
{
System.out.print(num3 + " ");
}
num3--;
}
System.out.println();
num4 = 2;
System.out.print("Table of each even integer and its square between 2 and 16 : ");
while(num4 <= 16)
{
System.out.println(num4+" t"+Math.pow(num4,2));
num4 = num4+2;
}
System.out.println();
}
}