Okay first things first here was my assignment:
secondly heres my code:Due: Monday, October 10th, 2011.
Main topics: User input
Basic String Methods
Boolean Expressions
if & if - else Statements
Program Specification:
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 of length three.
Displays this determination to the user in a reasonable report format.
Grading:
Performance Indicator [1] [2] [3]
Readability and documentation 1 2 2
Use of conditional operators 1 2 2
Functional requirements 2 3 4
Efficiency 1 2 2
Sample run(s):
Please enter a valid (3 character) double literal : 123
123 is a valid (3 character) double literal
Please enter a valid (3 character) double literal : 002
002 is a valid (3 character) double literal
Please enter a valid (3 character) double literal : +45
+45 is a valid (3 character) double literal
Please enter a valid (3 character) double literal : -45
-45 is a valid (3 character) double literal
Please enter a valid (3 character) double literal : 4.5
4.5 is a valid (3 character) double literal
Please enter a valid (3 character) double literal : 0.1
0.1 is a valid (3 character) double literal
Please enter a valid (3 character) double literal : 45.
45. is a valid (3 character) double literal
Please enter a valid (3 character) double literal : +.1
+.1 is a valid (3 character) double literal
Please enter a valid (3 character) double literal : -.1
-.1 is a valid (3 character) double literal
import java.util.Scanner; public class Weekly03 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub String literal; Scanner stdIN = new Scanner(System.in); System.out.print("Please enter a valid (3 character) double literal: "); literal = stdIN.nextLine(); if (literal.charAt(0) >= 0 && literal.charAt(0) <= 9) { if (literal.charAt(1) >= 0 && literal.charAt(1) <= 9) { if (literal.charAt(2) >= 0 && literal.charAt(2) <= 9 || literal.charAt(2) == '.') System.out.println(literal + " is a valid double literal!"); else System.out.println("Invalid input"); } else if (literal.charAt(1) == '.') { if (literal.charAt(2) >= 0 && literal.charAt(2) <= 9) System.out.println(literal + " is a valid double literal!"); else System.out.println("Invalid input"); } else if (literal.charAt(0) == '+' || literal.charAt(0) == '-') { if (literal.charAt(1) >= 0 && literal.charAt(1) <= 9) { if (literal.charAt(2) >= 0 && literal.charAt(2) <= 9 || literal.charAt(2) == '.') System.out.println(literal + " is a valid double literal!"); else System.out.println("Invalid input"); } else if (literal.charAt(1) == '.') { if (literal.charAt(2) >= 0 && literal.charAt(2) <= 9 ) System.out.println(literal + " is a valid double literal!"); else System.out.println("Invalid input"); } } else if (literal.charAt(0) == '.') { if (literal.charAt(1) >= 0 && literal.charAt(1) <= 9) { if (literal.charAt(2) >= 0 && literal.charAt(2) <= 9) System.out.println(literal + " is a valid double literal!"); else System.out.println("Invalid input"); } else System.out.println("Invalid input"); } } } }
i thought i hit all possible valid combinations with my if, else if statements, yet when i run the program i get no output. it just is blank after i enter the possible entries. I am VERYY NEW to java this is like our 3rd assignment in class and I'm just looking for any help.