Question

Please write a java program that takes in user input of various numbers as a type...

Please write a java program that takes in user input of various numbers as a type string, prints the sum of all numbers entered, and prints the smallest and largest numbers. Arrays are optional as they have not been covered by my professor yet. Thank you

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note : i didnt used arrays ..I used substring

Could you plz go through this code and let me know if u need any changes in this.Thank You
_________________

// SumOfNumbersMInMax.java

import java.util.Scanner;

public class SumOfNumbersMInMax {

   public static void main(String[] args) {
       int min,max,sum=0,val;
       min=Integer.MAX_VALUE;
       max=Integer.MIN_VALUE;
       int indx=0,flag=0;
       String str=null;
       /*
       * Creating an Scanner class object which is used to get the inputs
       * entered by the user
       */
       Scanner sc = new Scanner(System.in);  
       System.out.println("Enter ( numbers seperated by space ):");
       str=sc.nextLine();
      
       indx=str.indexOf(" ");
       while(indx!=-1 || flag==0)
       {
           if(indx==-1)
           {
               flag=1;
               val=Integer.parseInt(str.substring(0));  
              
           }
           else
           {
               val=Integer.parseInt(str.substring(0,indx));
           }
          
           sum+=val;
           if(min>val)
           {
               min=val;
              
           }
           if(max<val)
           {
               max=val;
           }
          
          
          
           str=str.substring(indx+1);
           indx=str.indexOf(" ");
       }
  
       System.out.println("Sum :"+sum);
       System.out.println("Minimum :"+min);
       System.out.println("Maximum :"+max);
      
   }

}
___________________________

Output:

Enter ( numbers seperated by space ):
12 23 34 45 56 6 1 67 75 32 89 92 12 55 77
Sum :676
Minimum :1
Maximum :92

_______________Could you plz rate me well.Thank You

Add a comment
Know the answer?
Add Answer to:
Please write a java program that takes in user input of various numbers as a type...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using Java write a program that takes a string input from the user and then outputs...

    Using Java write a program that takes a string input from the user and then outputs the first character, then the first two, then the first three, etc until it prints the entire word.

  • In java, write a program that gets 10 integer numbers from the user using user input,...

    In java, write a program that gets 10 integer numbers from the user using user input, and then calculates and display the sum of the numbers that have been read.   Program Requirements: Write the program in three versions with three loops. Put all three loops in the main method of your source code. version1:  use a while loop. version2:  use a do-while loop. version 3:  use a for loop. For each version, use a loop to input 10 int numbers from the user...

  • Write a Java program which takes a string as a user input. Create 2 functions. The...

    Write a Java program which takes a string as a user input. Create 2 functions. The first function expects a string as argument and returns void. It converts all upper case characters to lower case and converts all lower case characters to upper case. It then prints out the converted string to a console. The second function also expects a string as argument and returns void. It will find first charactor that is repeated exactly 2 times in the string....

  • Write a complete java program that prompts the user for their name and two numbers. The...

    Write a complete java program that prompts the user for their name and two numbers. The correct java methods and parameters must be passed to find the length of the name entered and return “TRUE” if the sum of numbers is even, or FALSE if the sum of numbers is odd: Notes included in the program Sample Program Please enter a name and I will tell you the length of the name entered John Then length of the name John...

  • Q1. Write a program in Java         a. Create 2 separate arrays, of user defined values,...

    Q1. Write a program in Java         a. Create 2 separate arrays, of user defined values, of same size         b. Add these 2 arrays. ........................................................................................................................... Q2. Write a program in java (using loop) input any10 numbers from user and store in an array. Check whether each of array element is positive, negative, zero, odd or even number. ............................................................................................................................ Q3. Write a program in Java to display first 10 natural numbers. Find the sum of only odd numbers. .............................................................................................................................. Q4....

  • Write a java program that will print if n numbers that the user will input are...

    Write a java program that will print if n numbers that the user will input are or not within a range of numbers. For that, your program needs to ask first for an integer number called N that will represent the number of times that will ask for other integer numbers. Right after, it should ask for two numbers that will represent the Min and Max for a range. Lastly. it will iterate N number times asking for an integer...

  • [JAVA] Suppose we need to write code that receives String input from a user, and we...

    [JAVA] Suppose we need to write code that receives String input from a user, and we expect the String input to contain a double value (inside quotes). We want to convert the String to a double using the static method Double.parseDouble(String s) from the Double class. The parseDouble method throws a NumberFormatException if the String s is not a parsable double. Write a method printSum that takes two String parameters (that hopefully have parsable doubles in them), and either prints...

  • Please write a java program that takes a large, user-entered number (usually 10 digits) and tallies...

    Please write a java program that takes a large, user-entered number (usually 10 digits) and tallies the 10 digits to be used in an array. Then, the method should tell the user how many of each number was input. For example, for the number 445903218, the program should say "2 4's, 1 5...," etc etc.

  • Write a C++ program that does the following: Asks the user to enter 3 integers, Obtains...

    Write a C++ program that does the following: Asks the user to enter 3 integers, Obtains the numbers from the user, Prints the largest number and then the smallest of the numbers, If the numbers are equal, prints the message: "These numbers are equal." Prints the sum, average, and product of the 3 numbers.

  • A Java Problem. E5.19 Write a program that takes user input describing a playing card in...

    A Java Problem. E5.19 Write a program that takes user input describing a playing card in the following shorthand notation: А Ace 2... 10 Card values Jack Queen King Diamonds Hearts Spades Clubs Your program should print the full description of the card. For example, Enter the card notation: QS Queen of Spades Implement a class Card whose constructor takes the card notation string and whose getDescription method returns a description of the card. If the notation string is not...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT