Question

1. Write a program that prompts the user to enter three integers and display the integers...

1. Write a program that prompts the user to enter three integers and display the integers in non-decreasing order. You can assume that all numbers are valid.

For example:

Input Result
140
-5
10
Enter a number: 
Enter a number: 
Enter a number: 
-5, 10, 140

import java.util.Scanner;
public class Lab01 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
  
}
}

----------------------------------------------------------------------------------------------------------------------------

2. Write a program that repeatedly prompts the user for integer values from standard input. The program then prints the square of each value until the user enters a sentinel value of -999, which causes the loop to exit. Do not print the sentinel value. You can assume that all integers are valid.

For example:

Input Result
1
-999
Enter a number:
The square of 1 is 1.
Enter a number:
-998
999
-999
Enter a number:
The square of -998 is 996004.
Enter a number:
The square of 999 is 998001.
Enter a number:
-999
999
-999
Enter a number:

import java.util.Scanner;
public class Lab00 {
   public static void main(String[] args) {
       Scanner input = new Scanner(System.in);
   }
}

---------------------------------------------------------------------------------------

3.

Write a program that repeatedly prompts the user for a line of alphabetical characters from standard input. The program then prints each line after making all characters in the sentence capitalized until the user enters an empty string, which causes the loop to exit. You can assume that the number of lines is always >1. You may find the input.hasNext() method is helpful.

For example:

Input Result
Hello world
Practice makes perfect

Enter a sentence:
HELLO WORLD
Enter a sentence:
PRACTICE MAKES PERFECT
Enter a sentence:

import java.util.Scanner;
public class Lab00 {
   public static void main(String[] args) {
       Scanner input = new Scanner(System.in);
   }
}

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

\color{red}\underline{1:}

import java.util.Scanner;

public class Lab01 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("Enter a number: ");
        int n1 = input.nextInt();
        System.out.println("Enter a number: ");
        int n2 = input.nextInt();
        System.out.println("Enter a number: ");
        int n3 = input.nextInt();

        int min = n1, max = n1;
        if (n2 < min) min = n2;
        if (n3 < min) min = n3;
        if (n2 > max) max = n2;
        if (n3 > max) max = n3;
        int middle = (n1 + n2 + n3) - (min + max);

        System.out.println(min + ", " + middle + ", " + max);
    }
}

\color{red}\underline{2:}

import java.util.Scanner;

public class Lab00 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n;
        while (true) {
            System.out.println("Enter a number: ");
            n = input.nextInt();
            if (n == -999)
                break;
            System.out.println("The square of " + n + " is " + (n * n) + ".");
        }
    }
}

\color{red}\underline{3:}

import java.util.Scanner;

public class Lab00 {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        String s;
        while (true) {
            s = input.nextLine();
            if (s.isEmpty())
                break;
            System.out.println(s.toUpperCase());
        }
    }
}
Add a comment
Know the answer?
Add Answer to:
1. Write a program that prompts the user to enter three integers and display the integers...
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
  • The program prompts the user to input three words, then display them in      sorted order....

    The program prompts the user to input three words, then display them in      sorted order. Strings have to be compared with compareTo method. */ import java.util.Scanner; public class Lab4Part13{     public static void main(String[] args){         Scanner input = new Scanner(System.in);         // Write rest of the code here     } }

  • Complete the following program so it prompts the user for 3 integers and displays the smallest...

    Complete the following program so it prompts the user for 3 integers and displays the smallest of the 3 numbers. For instance, if the user provided 7 4 and 12, then the program would display 4. import java.util.Scanner; public class Program3{ public static void main(String[] args) { Scanner kb = new Scanner(System.in);

  • (Process a string) Write a program that prompts the user to enter a string and displays...

    (Process a string) Write a program that prompts the user to enter a string and displays its length and its first character. java StringLength Enter a string:Does quantum determinacy have anything to with whether human cognition is deterministic? The string is of length 88 and the first character is D import java.util.Scanner; class StringLength{    public static void main (String args[]){        Scanner input = new Scanner(System.in);        System.out.println("Enter a string:");        String ans = input.nextLine();        System.out.println("The string...

  • Write a JAVA program that prompts the user for student grades and displays the highest and...

    Write a JAVA program that prompts the user for student grades and displays the highest and lowest grades in the class. The user should enter a character to stop providing values. Starter code: import java.util.Scanner; public class MaxMinGrades{   public static void main(String[] args){     Scanner input = new Scanner(System.in);     System.out.println("Enter as many student grades as you like. Enter a character to stop.");     double grade = input.nextDouble();     double minGrade = Double.MAX_VALUE;     double maxGrade = Double.MIN_VALUE;     while (Character.isDigit(grade)) {       if (grade == 0)...

  • Write a do-while loop that continues to prompt a user to enter a number less than...

    Write a do-while loop that continues to prompt a user to enter a number less than 100, until the entered number is actually less than 100. End each prompt with newline Ex: For the user input 123, 395, 25, the expected output is: Enter a number (<100): Enter a number (<100): Enter a number (<100): Your number < 100 is: 25 import java.util.Scanner; public class NumberPrompt { public static void main (String [] args) { Scanner scnr = new Scanner(System.in);...

  • Please put both of this loops into one program. Set it up so that there is...

    Please put both of this loops into one program. Set it up so that there is one main function and both loops are within it. Thank You. import java.util.Scanner; public class WhileDavidMungomaLab12 { public static void main(String[] args) { int aScore = -1; while (aScore < 0 || aScore > 100) { Scanner sc = new Scanner(System.in); System.out.println("Please enter a valid number that is within the specified range(0 and 100): "); aScore = sc.nextInt(); } } } AND import java.util.Scanner;...

  • Finish the given ProcessFile.java program that prompts the user for a filename and reprompts if file...

    Finish the given ProcessFile.java program that prompts the user for a filename and reprompts if file doesn’t exist. You will process through the file skipping any text or real (double) numbers. You will print the max, min, sum, count, and average of the integers in the file. You will want to create test files that contain integers, doubles, and Strings. HINT: Use hasNextInt() method and while loop. You may also want to use Integer.MAX_VALUE and Integer.MIN_VALUE for the initialization of...

  • Write a program that reads a person's first and last names, separated by a space. Then...

    Write a program that reads a person's first and last names, separated by a space. Then the program outputs last name, comma, first name. End with newline. Example output if the input is: Maya Jones Jones, Maya import java.util.Scanner; public class SpaceReplace {    public static void main (String [] args) {       Scanner scnr = new Scanner(System.in);       String firstName;       String lastName; //answer goes here//    } }

  • Hello! I'd greatly appreciate it if someone could help me out with this problem. "Complete the...

    Hello! I'd greatly appreciate it if someone could help me out with this problem. "Complete the following program, which should allow the user to repeatedly enter input until a sentinel value of 0 is seen. Once input has finished, the program should show the average of the user's data, excluding the sentinel value itself. You may assume that the user will enter at least one non-sentinel value" import java.util.Scanner; public class SentinelValue { public static void main(String [] args) {...

  • C++ Write a program that prompts the user to enter integers or a sentinel to stop....

    C++ Write a program that prompts the user to enter integers or a sentinel to stop. The program prints the highest and lowest numbers entered, the sum and the average. DO NOT USE ARRAYS, only variables and loops. Write a program the prompts the user to input a positive integer. Keep asking the user until a positive integer is entered. Once a positive integer is entered, print a message if the integer is prime or not. (NOTE: A number is...

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