Question

//Beginner level we haven't done for loops yet but we have done if and if else...

//Beginner level we haven't done for loops yet but we have done if and if else statements so can you please use that?

Write a Java program that reads the ages of three persons from the user, and decides who is the oldest, and who the youngest person is.

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

ANSWER: Here I am giving you the code and output if you have any problem then comment or like it please.

CODE:

import java.util.Scanner;

public class Age {

   public static void main(String[] args) {
           int a,b,c;
           Scanner sc= new Scanner(System.in);
           System.out.println("Enter the ages of three persons:");
           a=sc.nextInt();
           b=sc.nextInt();
           c=sc.nextInt();
           if(a>b && a>c) {
               System.out.println("First person is oldest.");
           }else if(b>a && b>c ) {
               System.out.println("Second person is oldest.");
           }else {
               System.out.println("Third person is oldest.");
           }
          
           if(a<b && a<c) {
               System.out.println("First person is youngest.");
           }else if(b<a && b<c) {
               System.out.println("second person is youngest.");
           }else {
               System.out.println("Third person is youngest.");
           }

   }

}

OUTPUT:

Add a comment
Know the answer?
Add Answer to:
//Beginner level we haven't done for loops yet but we have done if and if else...
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
  • THIS IS A VERY SIMPLE PROGRAM. WITHOUT ANY LOOPS (HAVE NOT LEARNED LOOPS YET) C++ BEGINNER...

    THIS IS A VERY SIMPLE PROGRAM. WITHOUT ANY LOOPS (HAVE NOT LEARNED LOOPS YET) C++ BEGINNER Write a program that asks for the cost of three items. Then calculate the sum of the costs and a 4% tax. Display the cost of each item, the sum of the items, the tax and the final bill.

  • JAVA CODE Beginner. please use if, else if or switch statements, but don't use arrays, please  ...

    JAVA CODE Beginner. please use if, else if or switch statements, but don't use arrays, please   Write a program that reads a string from the keyboard and tests whether it contains a valid date. Display the date and a message that indicates whether it is valid. If it is not valid, also display a message explaining why it is not valid. The input date will have the format mm/dd/yyyy. A valid month value mm must be from 1 to 12...

  • Hello! we are using Python to write this program. we are supposed to use loops in...

    Hello! we are using Python to write this program. we are supposed to use loops in this assignment. I would greatly appreciate the help! Thank you! Write a program that allows the user to play a guessing game. The game will choose a "secret number", a positive integer less than 10000. The user has 10 tries to guess the number. Requirements: we would have the program select a random number as the "secret number". However, for the purpose of testing...

  • This an intro class, we can't use 'i'f statements, yet No loops, it has to be...

    This an intro class, we can't use 'i'f statements, yet No loops, it has to be very simple, something somebody with little coding experience can do. We've learned about print, and basic math function in Python Coding, this is Eiffel Tower In this program, you will print out ascii art of the eiffel tower. Name your progam eiffel tower.py. Your program should ask the user for just one number: The size of the tower. The program should support any size...

  • Lanuage C++ (Beginner level) Please...I need help with this assignment If I still have question, can...

    Lanuage C++ (Beginner level) Please...I need help with this assignment If I still have question, can i contact you? -------------------------- Program 1 - WRITE ALL THE CODE in ONE FILE...   MyArrayPtrArith1.cpp Step 1 - Define the class Write a class, myArrayClass, that creates an integer array. * Add an 'arraySize' variable, initialize to zero ( default constructor function ) * Create int * ptrArray ( default constructor set to NULL ) * Add a default constructor ( see above for...

  • *** FOR A BEGINNER LEVEL JAVA CLASS, PLEASE KEEP CODE SIMPLE, AND WE USE BLUE J...

    *** FOR A BEGINNER LEVEL JAVA CLASS, PLEASE KEEP CODE SIMPLE, AND WE USE BLUE J IN CLASS (IF IT DOESNT MATTER PLEASE COMMENT TELLING WHICH PROGRAM YOU USED TO WRITE THE CODE, PREFERRED IS BLUE J!!)*** ArrayList of Objects and Input File Use BlueJ to write a program that reads a sequence of data for several car objects from an input file. It stores the data in an ArrayList<Car> list . Program should work for input file containing info...

  • This lab will create a digital clock based on nested FOR loops for hours, minutes, and...

    This lab will create a digital clock based on nested FOR loops for hours, minutes, and seconds, and a WHILE loop for doing over and over so that your clock works for all year long without interruption. Note: If a group of students is interested, we could create a real digital wall-mounted clock to be placed in our classroom, so I can keep track of the time during my lectures. The actual clock would be based on the LED Strip...

  • Practice C# Activity The purpose of this activity is to allow students to become accustomed to...

    Practice C# Activity The purpose of this activity is to allow students to become accustomed to the Visual Studio IDE and the differences in C# and Java. In this app, you will get practice working with C# I/O, if statements and loops. 1. Create a C# app for the Hollywood Movie Rating Guide, which can be installed in a kiosk in theaters. Each theater patron enters a value from zero to four indicating the number of stars that the patron...

  • Please do it like someone wouldve done it as a beginer programer. Dont use pointer unless...

    Please do it like someone wouldve done it as a beginer programer. Dont use pointer unless it asking for. /* Write a program designed to get ages and heights from the user, then find the average age, average height, and average age/height ratio. */ #include <stdlib.h> #include <stdio.h> #define MAXNUM 50 typedef struct person { int age; double height; } Person; int getData(Person people[], int max) /* Get the data from the user and put it in an array of...

  • I've done all questions except question 6. how do I do this? please help. code needs...

    I've done all questions except question 6. how do I do this? please help. code needs to be java 1. You need to be able to open and read the text files that have been provided for the project. Write a Java program that reads the driver.txt file and displays each data value for each line from the file to the screen in the following format: Licence Number: Licence Class: First Name: Last Name: Address: Suburb: Postcode: Demerit Points: Licence...

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