Write a program that inputs three different integers from th

Write a program that inputs three different integers from the keyboard, then prints the sum, the average, the product, the smallest and the largest of these numbers. Use only the single-selection form of the if statement. The screen dialogue should appear as follows: Enter three different integers: 13 27 14 Sum is 54 Average is 18 Product is 4914 Smallest is 13 Largest is 27 Write a program that inputs one number consisting of five digits from the user, separates the number into its individual digits and prints the digits separated from one another by three spaces each. For example, if the user types in the number 42339, the program should print 4 2 3 3 9

Solution

1)

SumAvgMinMax.java

import java.util.Scanner;

public class SumAvgMinMax {


   public static void main(String[] args) {
      
      
       //Declaring variables
       int a,b,c,sum=0,product = 1,min,max;
       double average=0;
      
       //Scanner object is used to get the inouits entered by the user
               Scanner sc=new Scanner(System.in);

              
               //creating an integer array of size 3
               int nos[]=new int[3];
              
              
               //getting the numbers entered by the user
               System.out.print(\"Enter Three Integers :\");
               for(int i=0;i<nos.length;i++)
               {
              
                   //populating user entered values into an array
               nos[i]=sc.nextInt();
              
              
               //calculating the sum
               sum+=nos[i];
              
               //calculating the product
               product*=nos[i];
               }
      
               //calculating the average
               average=sum/3;

               min=nos[0];
               max=nos[0];
              
               //calculating the minimum and maximum
               for(int i=0;i<nos.length;i++)
               {
                   if(min>nos[i])
                       min=nos[i];
                  
                   if(max<nos[i])
                       max=nos[i];
               }
              
               //displaying the results
               System.out.println(\"Sum is :\"+sum);
               System.out.println(\"Average is :\"+average);
               System.out.println(\"Product is :\"+product);
               System.out.println(\"Smallest is :\"+min);
               System.out.println(\"Largest is :\"+max);
   }

}

________________________

output:

Enter Three Integers :13 27 14
Sum is :54
Average is :18.0
Product is :4914
Smallest is :13
Largest is :27

___________________

2)

package org.students;

import java.util.Scanner;

public class NumberToDigits {

   public static void main(String[] args) {
      
//Declaring variables
int number,reverse_num, remainder;;
  
//Scanner class object is used to read the inputs enteredby the user
Scanner sc=new Scanner(System.in);
  
//Getting te number entered by the user
System.out.print(\"Enter a number :\");
number=sc.nextInt();
  
//Calling the method by passing the number as parameter
reverse_num=reverseDisplay(number);
  
  
System.out.print(\"The Individual Digits of a number \"+number+\" is :\");
  
//This while loop will split the number to individual digits
while (reverse_num != 0)
{
remainder = reverse_num % 10;

reverse_num= reverse_num / 10;

//Displaying the digits
System.out.print(remainder+\" \");
}

   }

/* This method takes the number as input and returns the reversed number
* Params :number of type integer
* Return :reverse number of type integer
*/
   private static int reverseDisplay(int number) {
       //Declaring variables
int temp=0;
int reverse_number=0;
  
//This while loop will reverse the number
while(number>0)
{
temp=number%10;
reverse_number=reverse_number*10+temp;
number=number/10;
}
return reverse_number;

   }

}

_________________________

output:

Enter a number :42339
The Individual Digits of a number 42339 is :4 2 3 3 9   

___________Thank You

 Write a program that inputs three different integers from the keyboard, then prints the sum, the average, the product, the smallest and the largest of these nu
 Write a program that inputs three different integers from the keyboard, then prints the sum, the average, the product, the smallest and the largest of these nu
 Write a program that inputs three different integers from the keyboard, then prints the sum, the average, the product, the smallest and the largest of these nu

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site