mardi 24 février 2015

Using while loop, if statement and, for loop for my project [on hold]

Output your name and Project 3



  1. Prompt for and read a character

  2. Repeat while the character is not ‘X’ a. Prompt for and read an integer b. If the integer is <= 0 or > 10 Print an error message Else if the character is not ‘A’..’D’ Print an error message Else print the design specified by the character (see the chart below) c. Prompt for and read another character

  3. Print program complete


‘A’ Print a left justified triangle with the longest row on the bottom


‘B’ Print a left justified triangle with the longest row on the top


‘C’ Print a right justified triangle with the longest row on the bottom


‘D’ Print a right justified triangle with the longest row on the top



import java.util.Scanner;

public class Project3 {

public static void main(String[] args) {
System.out.println("Lisa, Project 3");
Scanner in = new Scanner(System.in);
System.out.println("Please enter a character");
String character = in.next();

System.out.println("Please enter an integer");
int num = in.nextInt();
while(!character.equals("X"))
if(num <= 0 || num > 10){
System.out.println("Error");}
else if (!character.equals("A")){
System.out.println("Error");}
else if (!character.equals("B")){
System.out.println("Error");}
else if (!character.equals("C")){
System.out.println("Error");}
else if (!character.equals("D")){
System.out.println("Error");}

}
}


Dont really know what else to do. In need of major help


Aucun commentaire:

Enregistrer un commentaire