NEED JAVA PROGRAMMING FOR THE FOLLOWING List of programming

 NEED JAVA PROGRAMMING FOR THE FOLLOWING: List of programming questions  1) If m and n are integers, then sum(m,n) is the sum of all integers in the interval [m,n), which is 0 if the interval is empty. public static int sum(int m, int n){ /*...*/ }  2) If m and n are integers, then product(m,n) is the product of all integers in the interval [m,n), which is 1 if the interval is empty. public static int product(int m, int n){ /*...*/ }  3) If m and n are integers, countEvens(m,n) is the number of even integers which are greater than m and less than n. public static int countEvens(int m, int n){ /*...*/ }  4) If m is an integer, sumUpTo(m) is the sum of the integers in [0,m). public static int sumUpTo(int m){ /*...*/ }  5) If m is an integer, digits(m) is the number of decimal digits in the shortest decimal expansion of m. For example, digits(493) is 3, digits(0) is 1, and digits(-33) is 2. public static int digits(int m){ /*...*/ } 

Solution

1)

import java.util.Scanner;
public class sumofNum{

public static void main(String []args){
int x, y, temp,i,sum;
System.out.println(\"Enter interval to calculate their sum \");
Scanner in = new Scanner(System.in);
x = in.nextInt();
y = in.nextInt();
if (x>y)
{
temp=x;
x=y;
y=x;
}
sum=0;
for (i=x;i<y;i++)
sum=sum+i;
  
System.out.println(\"Sum of entered integers = \"+sum);
}
}

2)

import java.util.Scanner;
public class ProductofNum{

public static void main(String []args){
int x, y, temp,i,product;
System.out.println(\"Enter interval to calculate their product \");
Scanner in = new Scanner(System.in);
x = in.nextInt();
y = in.nextInt();
if (x>y)
{
temp=x;
x=y;
y=x;
}
product=1;
for (i=x;i<y;i++)
product=product*i;
  
System.out.println(\"product of all integers in interval = \"+product);
}
}

3)

import java.util.Scanner;
public class EvenCount{

public static void main(String []args){
int x, y, temp,i,evencount;
System.out.println(\"Enter two integers to calculate their product \");
Scanner in = new Scanner(System.in);
x = in.nextInt();
y = in.nextInt();
if (x>y)
{
temp=x;
x=y;
y=x;
}
evencount=0;
for (i=x;i<y;i++)
{
if (i%2==0)
{
evencount++;
}
}

  
System.out.println(\"Even count of integers in interval = \"+evencount);
}
}

4)

import java.util.Scanner;
public class Sumupto{

public static void main(String []args){
int x, y, temp,i,sum=0;
System.out.println(\"Enter integer to calculate sum upto integer \");
Scanner in = new Scanner(System.in);
x = in.nextInt();
  
  
  
for (i=0;i<x;i++)
{
sum=sum+i;
}

  
System.out.println(\"sum upto integer = \"+sum);
}
}

5)

import java.util.Scanner;
public class DigitsCount{

public static void main(String []args){
int x,No_of_digits;
System.out.println(\"Enter integer to calculate number of digits \");
Scanner in = new Scanner(System.in);
x = in.nextInt();
  
No_of_digits=(int)(Math.log10(x)+1);

  
System.out.println(\"no of digits in the integer = \"+No_of_digits);
}
}

 NEED JAVA PROGRAMMING FOR THE FOLLOWING: List of programming questions 1) If m and n are integers, then sum(m,n) is the sum of all integers in the interval [m,
 NEED JAVA PROGRAMMING FOR THE FOLLOWING: List of programming questions 1) If m and n are integers, then sum(m,n) is the sum of all integers in the interval [m,
 NEED JAVA PROGRAMMING FOR THE FOLLOWING: List of programming questions 1) If m and n are integers, then sum(m,n) is the sum of all integers in the interval [m,

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site