Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I`ve just learned basic stuffs of java(Basic String Methods, Boolean Expressions

ID: 3675584 • Letter: I

Question

I`ve just learned basic stuffs of java(Basic String Methods, Boolean Expressions, if & if - else Statements, Loop Statements)

so don`t use too much advance code, please and code must be included loop statements( While or do or for)

Program Specication:
Write a Java program that does the following:

• Prompts the user to input exactly three characters, which constitude a valid double literal in Java

. • Gets whatever the user enters and stores it into a String variable, using the the Scanner’s .nextLine() method.

• Determines if the input string is indeed a valid double literal : 1. Consists of exactly the following characters: ’+’, ’-’, ’.’ (decimal point), and ’0’ through ’9’ 2. The ’+’ or ’-’ character may only appear (once) as the rst character. 3. The ’.’ (decimal point) character must appear exactly once. 4. All other characters must be the ’0’ through ’9’ characters.

• Displays this determination to the user in a reasonable report format.

Sample run(s):

Please enter a valid double literal : 12345

12345 is not a valid double literal

Please enter a valid double literal : 1+23.45

1+23.45 is not a valid double literal

Please enter a valid double literal : +45

+45 is not a valid double literal

Please enter a valid double literal : 4.5

4.5 is a valid double literal

Please enter a valid double literal : 45.

45. is a valid double literal

Please enter a valid double literal : .45

.45 is a valid double literal

Please enter a valid double literal : +.12345

+.12345 is a valid double literal

Please enter a valid double literal : -1.

-1. is a valid double literal

Explanation / Answer

import java.util.Scanner;

public class assignmentFour

{

import java.util.Scanner;

public class public static void main(String[] args)

{

Scanner stdIn = new Scanner(System.in);

String literal;

char one;

char two;

char three;

System.out.println("Please enter a valid (3 characters) double literal: ");

literal = stdIn.nextLine();

if (literal.length() == 3)

{

one = literal.charAt(0);

two = literal.charAt(1);

three = literal.charAt(2);

}

}

}   

import java.util.Scanner;

public class assignmentFour
{
   public static void main(String[] args)
   {
       Scanner stdIn = new Scanner(System.in);
      
       String literal;
       char one;
       char two;
       char three;
      
       System.out.println("Please enter a valid (3 characters) double literal: ");
       literal = stdIn.nextLine();
      
       if (literal.length() == 3)
       {
          >            two = literal.charAt(1);
           three = literal.charAt(2);
       }
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote