cbolts 11-15-2004, 06:21 AM For my intro to java class I have to write a simple prog that does this
Part1: (5 marks)
Write an application to produce the following pattern. Use 2 nested for statements. to display one single character inside inner loop.
AAAA
BBB
CC
D
Hint: character variables are represented as numbers, arithmetic operations can be performed on characters.
Ex.
char var = 'a'; //var holds a
var ++; //var holds b
____________________________________________________________
and heres what I've got, but its not displaying anything for me:
/*
* Author: Casey Bolton
* Date: 10/26/04
* Purpose:
*/
import java.applet.Applet;
import java.awt.*;
//import java.io.*;
public class Lab6Char extends Applet{
public void paint(Graphics g){
int y =10;
int q = 4;
for(char v= 'a'; v <='d';v++){
int x=5;
for(int t=1; t>=q; t++){
g.drawString(""+v,x,y);
x=x+10;
}
}
q=q-1;
y=y+10;
}
}
Brandoe85 11-15-2004, 06:36 AM You've got the wrong forum, this is javascript, ask a mod to move it to the computer programming forum :thumbsup:
cbolts 11-15-2004, 06:42 AM What do you mean? This is written in java?
Brandoe85 11-15-2004, 06:45 AM Java is the programming language you are doing. This is the Javascript forum, it's a scripting language. Two totally different things
turbowrx 11-16-2004, 04:11 AM The code below will give you the looping and character changing.
You'll have to adapt it to run in an applet, which won't take much, but I can't do the whole thing for you. Good luck.
int q = 4;
int t = 4;
char c = 'A';
for(int i = 0; i < t; i++){
for(int v = 0; v < q; v++){
System.out.print("" + c);
}
System.out.println();
c++;
q--;
}
Spookster 11-16-2004, 04:28 AM The code below will give you the looping and character changing.
You'll have to adapt it to run in an applet, which won't take much, but I can't do the whole thing for you. Good luck.
int q = 4;
int t = 4;
char c = 'A';
for(int i = 0; i < t; i++){
for(int v = 0; v < q; v++){
System.out.print("" + c);
}
System.out.println();
c++;
q--;
}
I hope you get a good grade on his homework assignment. :rolleyes: It is against our ethics here at CodingForums to do other people's homework assignments. That is called cheating. Please do not do that again. You might think you are helping but you really aren't. The point of a homework assignment is for that student to learn. By doing it for them all they learned is how to cheat on future assignments.
jettlarue2003 11-17-2004, 11:12 PM Originally Posted by Spookster
I hope you get a good grade on his homework assignment. It is against our ethics here at CodingForums not to do other people's homework assignments. That is called cheating. Please do not do that again. You might think you are helping but you really aren't. The point of a homework assignment is for that student to learn. By doing it for them all they learned is how to cheat on future assignments.
why r u mad. you said it was good to do other peoples assigs!?!
ragol_67 11-18-2004, 12:31 AM No, he is saying that by doing another users homework assignment, you are aiding in his cheating. Homework is meant for students to learn the required necessities of the subject, and by not doing them, they are only hindering themselves.
Antoniohawk 11-18-2004, 12:54 AM Ragol and Spookster are both right. I'm wondering jettlarue2003, did you join the forums just to point out Spookster's typo, as this is your first post?
ghell 11-21-2004, 02:57 PM why r u mad. you said it was good to do other peoples assigs!?!
='D thanks man, i needed that
making fun of people is fun :D (plz dont make fun of me *puppy dog eyes*
anyway, i dont really see how someone could answer this without doing it for him, and its pretty simple (if i could do it it must be)
edit: although you could have done it only usnig 3 variables like this:
char c = 'A';
for(int i=4; i>0; i--)
{
for(int j=0; j<i; j++)
{
System.out.print(c);
}
System.out.println();
c++;
}
you could even have used c instead of i (as long as you incremented and subtracted to get the char value to 1 for A (im guessing its 65, so just subtract 64;), and where it prints c you print the inverse of it, so althoguh c would be D you could just subtract for it to be A)
anyway, theres a lil uselessnes for ya
whackaxe 11-21-2004, 05:37 PM there are 2 fundemental problems with this thread
1) 4 posts dedicated to subject of homework when poster should have read homework policy
2) 3 posts of confusion between javascript and java........ when poster should have been using C++ :D
sorry, just had to have a crack at java ;)
ghell 11-22-2004, 07:47 AM there are 2 fundemental problems with this thread
1) 4 posts dedicated to subject of homework when poster should have read homework policy
2) 3 posts of confusion between javascript and java........ when poster should have been using C++ :D
sorry, just had to have a crack at java ;)
and one useless post about how useless half of these posts are :p
shmoove 11-22-2004, 08:41 AM and one useless post about how useless half of these posts are :p
Make that three.
shmoove
CptnCrlyBrace 11-26-2004, 05:12 AM I HAVE THIS HOMEWORK ASSIGNMENT???Just tryn to break the ice... You are right? The teacher I had for this said he would point us in the right direction// maybe our notes or to the book.
|
|