Computer Science, asked by mohameddsoliman99999, 1 month ago

Write a java program that asks user to enter a number until user enters -1.
Then the program should display the sum of all entered numbers except
for -1.

Answers

Answered by Anonymous
0

\Huge\sf{Answer:-}

ort java.util.Scanner;

public class JavaLoopExcercise

{

public static void main(String[] args)

{

Scanner console = new Scanner(System.in);

int number;

int max = Integer.MIN_VALUE;

int min = Integer.MAX_VALUE;

char choice;

do

{

System.out.print("Enter the number ");

number = console.nextInt();

if(number > max)

{

max = number;

}

if(number < min)

{

min = number;

}

System.out.print("Do you want to continue y/n? ");

choice = console.next().charAt(0);

}while(choice=='y' || choice == 'Y');

System.out.println("Largest number: " + max);

System.out.println("Smallest number: " + min);

}

}

Similar questions