import java.util.Scanner;  public class SortedNames {      public static void main(String[] args) {          String name1;          String name2;          String name3;     Scanner keyboard=new Scanner(System.in);          System.out.print("Please Enter First Name: ");          name1=keyboard.nextLine();          System.out.print("Please Enter Second Name: ");          name2=keyboard.nextLine();          System.out.print("Please Enter Third Name: ");          name3=keyboard.nextLine();          if((name2.compareToIgnoreCase(name1)<0)&&(name2.compareToIgnoreCase(name3)<0))          {              System.out.println(name2);          }          if((name1.compareToIgnoreCase(name2)<0)&&(name1.compareToIgnoreCase(name3)<0))          {              System.out.println(name1);          }          if((name3.compareToIgnoreCase(name1)<0)&&(name3.compareToIgnoreCase(name2)<0))          {              System.out.println(name3);          }    }       }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Need helped with question 3 screenshot provided & my Java code work is typed below.

Step 1 -

import java.util.Scanner; 
public class SortedNames { 
    public static void main(String[] args) { 
        String name1; 
        String name2; 
        String name3; 
   Scanner keyboard=new Scanner(System.in); 
        System.out.print("Please Enter First Name: "); 
        name1=keyboard.nextLine(); 
        System.out.print("Please Enter Second Name: "); 
        name2=keyboard.nextLine(); 
        System.out.print("Please Enter Third Name: "); 
        name3=keyboard.nextLine(); 

        if((name2.compareToIgnoreCase(name1)<0)&&(name2.compareToIgnoreCase(name3)<0)) 
        { 
            System.out.println(name2); 
        } 

        if((name1.compareToIgnoreCase(name2)<0)&&(name1.compareToIgnoreCase(name3)<0)) 
        { 
            System.out.println(name1); 
        } 

        if((name3.compareToIgnoreCase(name1)<0)&&(name3.compareToIgnoreCase(name2)<0)) 
        { 
            System.out.println(name3); 
        } 
  }      

 

Step 2 - 

Java program source code that prompts the user to enter a year value from the keyboard. Then check if the year is a leap year or not. Then find the year is a leap year or not. 

//LeapyearDemo.java 

import java.util.Scanner; 
public class LeapyearDemo  

 public static void main(String[] args)  
 { 
  boolean leapYear=false; 
  //create an instance of the Scanner class to read input from keyboard 
  Scanner keyboard=new Scanner(System.in);  
        System.out.print("Please enter year value : ");  
        int year=Integer.parseInt(keyboard.nextLine()); 
         
        /*Checking if year is multiple of 4 and not multiple of 100 then 
         * set the leapYear to true*/ 
        if((year%4==0) && (year%100!=0)) 
         leapYear=true; 
        /*checking if year is multiple of 400 then  
         * set leapYear to true otherwise set false*/ 
        else if(year%400==0) 
         leapYear=true; 
        else 
         leapYear=false; 
         
        if(leapYear) 
         System.out.println(year+" is a leap year."); 
        else 
         System.out.println(year+" is not a leap year."); 
         
 } 

3. Write a program to repeatedly read integers from the standard input until it reads -1 and exits.
For each number before -1, if it is positive and odd, do the following:
• Output a triangle like the one below with the integer being the width of the triangle's bottom
or the number of asterisks of the bottom row. For instance, if the integer is 7, you would
display the triangle below:
Transcribed Image Text:3. Write a program to repeatedly read integers from the standard input until it reads -1 and exits. For each number before -1, if it is positive and odd, do the following: • Output a triangle like the one below with the integer being the width of the triangle's bottom or the number of asterisks of the bottom row. For instance, if the integer is 7, you would display the triangle below:
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 4 images

Blurred answer
Knowledge Booster
Unreferenced Objects
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education