i have a problem for this program .
how can i use the program in the middle..
i tried to put it IN .. but many error exist..

please help me with my program .. thanks..

here's the output:
Enter Name: Simplicio
Enter Password: pOLOtAn
1 Capital constant letter/s
4 lower case consonant letter/s
0 capital Vowel letter/s
4lower case Vowel letter/s
Try Again?

import java.io.*;
import java.awt.Graphics;
import java.util.Random;
import javax.swing.*;
import java.util.Scanner;

public class midquiz
{
public static void main (String [] args) throws IOException
{
//try
{
Scanner input = new Scanner(System.in);

String name,pass,ans;
String pass1="pOLOtAn";
int len;
char len1[];
len1 = new char[20];


do
{

System.out.println ("Username must be 8 to 15 character only.");
System.out.print("Enter Username:");
name = input.nextLine();
len = name.length();

if (len>= 8 && len<=15)
{
for (int b=0;b<1;b++)
{
System.out.print("Enter Password:");
pass=input.nextLine();
if(pass.equals(pass1))
{
System.out.print("Alphabetical Order of your name is:");
for (int c=0;c<len;c++)
{
len1[c]=name.charAt(c);
}

//for(int d=1;d<len;d++)
//{
// if (let[c]>let[d])
// {
// char temp=let[c];
// let[c]=let[d];
// let[d]= temp;
// }
// }

for (int c=0;c<len;c++)
{
System.out.println(len1[c]+"");
}
}
else
{
System.out.println("You Have Enter Wrong PassWord ");
System.exit(0);
}


}


}
else
{
System.out.println("ILLEGAL USER! GOODBYE....");
System.exit (0);
}


System.out.println("\n Try Again? [Yes/No]:");
ans=input.nextLine();

}while (ans.equalsIgnoreCase ("Yes"));

}

} 
}

what exactly is the problem? it is a little unclear to me...

what exactly is the problem? it is a little unclear to me...

uuhhmm..

the main problem of this program is..

i can't use the middle part of the code ,,

there is something wrong ..

it cannot run when i use the middle part of my program ..

hhmm.. sorry for my unclear explanation ..

please help me.. for this.. thanks alot..

it doesn't look like your code is written to do too much...

it runs fine, but fine depends on what you want it to do. if you are referring to the alphabetical ordering of characters, well it isn't happening because all you are doing is print the characters of the username in chronological order.

does that help?

It doesn't work because you declared a variable, "c", inside of a for loop. When that for loop ended, that variable went out of scope (was destroyed). So in the next for loop where you tried to refer to "c", the compiler has no idea what you're talking about.

it doesn't look like your code is written to do too much...

it runs fine, but fine depends on what you want it to do. if you are referring to the alphabetical ordering of characters, well it isn't happening because all you are doing is print the characters of the username in chronological order.

does that help?

i want it to be like the said output ..
how will i do it?

please help me..

See my post above yours. Then declare "c" on the correct scope level (i.e. declare it outside of the for loop). Then see if you're still getting errors. Post any errors you're getting.

.. can you suggest or show me some code that suit for my program?

hhmm.. just asking for your consideration ..

im really sorry ..

Here you go. It's a bit rough, but it does what you wanted.
The main reason it's tough to understand is because you didn't
split all your code into separate methods. If you had defined different things using individual methods and then strung it all together in main then everything would be a lot more readable.

import java.util.Scanner;

public class midquiz {
// Variables
private static String name; 
private static String passInput;
private static String ans;
private static CharSequence userPass="PasswOrd";
private static int length;
private static int passLength;
private static int upperVowel = 0;
private static int upperConsonant = 0;
private static int lowerVowel = 0;
private static int lowerConsonant = 0;

public static void main (String [] args) {
	Scanner input = new Scanner(System.in);

	// Prompt for username
System.out.print("Enter Username: ");
name = input.nextLine();
length = name.length();

// Check appropriate length
if (length < 8 || length > 15) {
	System.out.print("Username must be between 8 and 15 characters in length.");
	return;
} else;
// If name appropriate, then continue
// Prompt for password
System.out.print("Enter Password: ");
passInput = input.nextLine();

// Verify password
if (passInput.contentEquals(userPass)) {
	System.out.println("Password valid.");
	
// If password is correct:
	for (;;) {
		passLength = passInput.length();
		upperVowel = 0;
		upperConsonant = 0;
		lowerVowel = 0;
		lowerConsonant = 0;
		
	// Count the number of uppercase and number of lowercase consonants and vowels.
	for (int i = 0; i < passLength; ++i) {
		
		Character letter = new Character(passInput.charAt(i));
		boolean isUpperCase = Character.isUpperCase(letter);
		boolean isLowerCase = Character.isLowerCase(letter);
		if (isUpperCase == true) {
			
			// Identifying vowels
			if ( letter.equals('A') || letter.equals('E') || 
				letter.equals('I') || letter.equals('O') || 
				letter.equals('U')) {
				// If it's a vowel then increase capitalized vowel count
				++upperVowel;
				
				// ...otherwise, increase capitalized consonant count
			} else {
				++upperConsonant;
			}
				
		} else if (isLowerCase == true){
			
			// Identifying vowels
			if (letter == 'a' || letter == 'e' || 
					letter == 'i' || letter == 'o' || 
					letter == 'u' ) {
				// If it's a vowel then increase lowercase vowel count
				++lowerVowel;
				
				// ...otherwise, increase lowercase consonant count
			} else {
				++lowerConsonant;
			}
 
		} else {
			// If you wanted to count digits as well, you could add that here.
		}
	}
	
	System.out.println("There are " +upperVowel+ " uppercase vowels.");
	System.out.println("There are " +upperConsonant+ " uppercase consonants.");
	System.out.println("There are " +lowerVowel+ " lowercase vowels.");
	System.out.println("There are " +lowerConsonant+ " lowercase consonants.");
	
	System.out.println("Try again (Re-count)? [Yes/No]: ");
	ans = input.nextLine();
	if (ans.equalsIgnoreCase("no")) {
		System.exit(0);
	}
	else if (ans.equalsIgnoreCase("yes")) {
		
	} else {
		System.out.println("Invalid choice. Try again?");
	}
	
}	
}

else;
// If password is incorrect:
System.out.println("Invalid password.");
System.out.println("Try Again? [Yes/No]:");
ans=input.nextLine();
// If no
if (ans.equalsIgnoreCase("no")) {
System.exit(0);
}
else;

// Whatever you want it to do.


}

}
commented: I've gone through 3 threads today, and you've helped in 2 of them. Nice to see such helpful people. Keep up the good work :) +1

um.... why?

don't do the homework of others.

um.... why?

don't do the homework of others.

I felt like it. There's only so much you can do in Beijing right now, with the censorship and all.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.