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
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
Please write a java program that takes in user input of various numbers as a type...
Write a java program that allows the user to input 20 double type numbers to an array and then output the largest (max) number.
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, 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...
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. The program must be in one file. version1: use a while loop. version2: use a do-while loop. version 3: use a for loop. For each version, use a loop to...
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 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, 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....
In Java, write a program using a loop that asks the user to enter a series of decimal numbers. The user must enter -88 to end the input of the decimal numbers. After the user enters all numbers, the program should display the sum of all numbers entered.
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.
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.