Remove this Banner Ad

Need Java Help

🥰 Love BigFooty? Join now for free.

Saint4Life

All Australian
Oct 10, 2002
830
128
Vic
AFL Club
St Kilda
Other Teams
saints
ok ive been stuck on this forever.. but i need some help

im trying to make

A
AB
ABC
ABCD
ABCDE

i have made

AA
AB
AC
AD
AE

BA
BB
BC
BD
BE

CA
CB
etc etc..

here is my coding so far, its very wrong :( needs help.

------------

class Exercise6{
public static void main(String[] args) {
char i = 65 ;
char j = 65 ;
System.out.println("\n ASCII Value") ;
for(i = 65 ; i<=69 ; i++){
for(j = 65 ; j<=69 ; j++){
System.out.println(" " +i +j) ;
}
System.out.print("\n") ;
}
}
}


-----------

thanks.
 
How about
Code:
class Exercise6{
   public static void main(String[] args) {
   char i = 65 ;
   System.out.println("\n ASCII Value") ; 

   for(j=0 ; j<5 ; j++){ // create an incremental value for each line
      System.out.println(" " +i) ;

      for(k = 0 ; k<j ; k++){// print out the desired number of chracters
          System.out.print(+ (i+k)) ;
     }
     System.out.print("\n") ;
  }
}


haven't tested it but
 
Some errors in your code Jim Boy, I've tweaked it.

Code:
char i = 'A' ;
System.out.println("\n ASCII Value") ; 

for(int j=0 ; j<5 ; j++){ // create an incremental value for each line
    System.out.print(i) ;

    for(int k = 1 ; k<=j ; k++){// print out the desired number of chracters
        System.out.print((char) (i+k)) ;
    }
    System.out.print("\n") ;
}
 
Here's another solution I came up with, essentially the same, but probably harder to understand:

Code:
       char i = 'A';
       System.out.println("ASCII Value") ; 

       for (int j = 0; j < 5; j++) {
           for (char c = i ; c <= (char) (i + j) ; c++) {
               System.out.print(c);
           }
           System.out.println();
       }
 

Log in to remove this Banner Ad

Remove this Banner Ad

Need Java Help

🥰 Love BigFooty? Join now for free.

Back
Top