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);          }    }       }

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter5: Control Structures Ii (repetition)
Section: Chapter Questions
Problem 14PE
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
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning