rotten69 20 Posting Whiz

Hey everyone,

I'm just wondering what level and type of maths are needed in solving programming problems. I was looking at maths courses the other day but I was unsure which one would suit my need as I'm an IT guy.

Can anyone suggest something? I want to be able to program in Java and solve problems quickly. So I want something to help me with my programming logic.


Cheers,

rotten69 20 Posting Whiz

a neater way of getting values from an array! Good work, buddy.

System.out.println ( "All the values in the array are: " );
for ( T x: array1 )
  System.out.println ( x );

Thanks.

peter_budo commented: Now let me "repay" your "kindness" of false accusation by down-voting so you can see that first vote wasn't my. Have nice day, and get some manners. -4
rotten69 20 Posting Whiz

You need to add all your code in between these tags [ code ] [/ code ] Just to give us an easy time to debug errors in your code.

Cheers,

rotten69 20 Posting Whiz

I didn't want HIM to give me the code. I wanted to know where the problem in the loop was and more importantly, I wanted to learn. In fact, I was a bit surprised that the equal sign could cause the problem.

rotten69 20 Posting Whiz

Thanks for the brief explanation..

rotten69 20 Posting Whiz

The equal sign in my condition was causing the problem. But, in plain English, we say that since nums is less or equal to the size of our array, treble nums by 3. That's why I initially thought that the condition shouldn't be problematic.

Thanks for the explanation.

rotten69 20 Posting Whiz

I know a few things in Java so I ain't completely a dummy. But, I do struggle with the thinking outside the box! At the moment, I'm trying to learn from a book called "Thinking in Java". It really seems pretty useful.

Thanks buddy for passing by and suggesting the website and books' names.

rotten69 20 Posting Whiz

I got my method printing out the values that I pass to it, and after being multiplied by three. I'm, however, still getting the same error as before. I still don't know why.


Here is the code

public static int treble(int[] nums){
	for (int i=0; i <= nums.length; i++){
		nums[i] = 3*nums[i];
		println("array [" + i + "] = " + nums[i] );
	}
	return 1;
		
}
public static void main (String [] args){
	int[] array = {2,4,6, 10, 20};
	treble(array); 
}

Cheers,

rotten69 20 Posting Whiz

Hi everyone,


I'd like to ask our Java experts a simple question about learning Java. I want to know how to learn a programming language in easy steps(if possible) especially Java. Would anyone suggest a good way of learning it and improving the way that from how a normal person thinks to a good programmer's way of thinking?

I want to build pretty solid foundations in my programming skills. Suggestions/advice/proven ways/ personal experience will be so much appreciated.

Thanks to all.

rotten69 20 Posting Whiz

In my opinion, that shouldn't be a problem because I haven't specified values for indexes 2 and 3. However, I changed the number of elements in my array to two elements and I'm still getting the same error. Anyway, thanks for your comment.

rotten69 20 Posting Whiz

How is that causing the problem?

rotten69 20 Posting Whiz

Hey everyone,

I'm wondering why I can't print the values that are in the array. I'm passing an array to the method below and trying to print the result.. the compiler says that "ArrayIndexOutOfBoundsException"

What's the problem really?

public static int[] treble(int[] nums){

		for (int i=0; i <= nums.length; i++){
			nums[i] = 3*nums[i];
		}
		return nums;
		
}

in the main method, I have   int[] array = {1,2,4};
                              system.out.println(treble(array));
rotten69 20 Posting Whiz

I figured it out by now..

rotten69 20 Posting Whiz

This is what I had before looking at the code you posted ... Thumb's up, buddy..

for (int a=0;a <= 5; a++){
			
			for( int b= 0; b <= 5; b++){
				println("b = " + b);
				if(b ==5)
					println("loop terminated " + b);
			}
		
		}
rotten69 20 Posting Whiz

@ zeroliken .. I ain't sure how to use a counter in Java ;p

rotten69 20 Posting Whiz

I want my program to print Loop terminated ** when the condition(b == 5) for the outer loop evaluates to true.. For example, after the first iteration, it will print "Loop terminated 1" and for the second, it will be "Loop terminated 2" and so on.

To avoid having five lines that tell me Loop terminated 1,2,3,4,5 after the first iteration and second and third...

cheers,

rotten69 20 Posting Whiz

How would I get the result I want? Would you suggest something?

rotten69 20 Posting Whiz

But why does b start at 30000 and something? Shouldn't b increment by 1?

for (int a=0;a <= 5; a++){
			
			for( int b= 0; b <= 5; b++){
				println("b = " + b);
				for(int c=1; c<=b; c++){
					if(b ==5)
						println("loop terminated " + c);
				}
			}
		
		}

This code doesn't do what I want to do..


Cheers,

rotten69 20 Posting Whiz

Hi everyone,

I'm doing a little experiment on Java loops.. I came across these infinite loops and they never wanted to stop .... Could anyone explain these loops to me, please. Thanks in advance.

for (int a=0;a <= 5; a++){
			
		int c;
		int b= 6;

		for( c=0; c <= b; b++){
			println("b = " + b);
				if(b ==5){
				      println("loop terminated " + c++);
				}
		}
		
	}

The idea was to get something to look like this
0
1
2
3
4
5
Loop terminated 1
0
1
2
3
4
5
Loop terminated 2 and so on till it gets to loop number 5 then breaks...

rotten69 20 Posting Whiz

Try using print_r($rows. " ".$rows); if this isn't working then give this a go...


while(mysql_affected_rows($ret)>=1){
DO SOMETHING;
}

rotten69 20 Posting Whiz

Thanks for the website.

rotten69 20 Posting Whiz

Did you want just the MAXimum value out of that set of numbers you provided us??

rotten69 20 Posting Whiz

You need to be a bit precise with the number of rows when querying a DB.
Try this code... I hope this solves your problem beautifully...

$sql="insert into emp1 values('abc','1c1',2004)";
if(mysql_query("$sql"))
{
      echo "1 record added";
}else{
      die("error ".mysql_error());
}

$ret=mysql_query("select * from emp1");

while($rows=mysql_fetch_array($ret) >= 1)
{
echo $rows['ename']. " ".$rows['eno'];
echo "<br>";
}
rotten69 20 Posting Whiz

You don't need the ID attribute because when you use these $_GET or $_POST, they look for the name attribute. In your case, it is name='memberIdd'

Cheers,

rotten69 20 Posting Whiz

if this solves your problem, please kindly mark it as a solved thread.

rotten69 20 Posting Whiz

Change the attribute ID to name in your form. This will fix the problem. If it doesn't, then try the steps below:

Delete the $ sign before table name in your query

$sql="SELECT * FROM tbl_name WHERE username='$myusername' and password='$mypassword'";
if $count => 1

then Try checking if the username and password are typed.

$mypassword = $_POST['mypassword'];
$myusername = $_POST['myusername'];

if ( isset('$mypassword') && isset('$myusername') ){

DO SOMETHING 

}else{

echo "username: $myusername and password: $mypassword  are not correct";

}
rotten69 20 Posting Whiz

I have noticed something wrong with your form.

<td align="right" width="130px">
    Username:
    </td>
    <td><input type="text" size="40" id="myusername" class="inputbox" /></td>
    </tr>
    <tr>
    <td align="right">
    Password:
    </td>
    <td><input type="password" size="40" id="mypassword" class="inputbox" /></td>

OK. Change the IDs for password to mypassword and for username to myusername. Try this and I'm sure it will work. The reason I'm telling you to do so Because you have got different names that don't match the names in your query.

rotten69 20 Posting Whiz

Hey there,

Try using $_REQUEST ... if this isn't working, then try renaming the ID and NAME in your form.

rotten69 20 Posting Whiz

Users are only allowed to select one option, Right? if so, then it's easy.

<form action= ""  method="POST"> 

Your checkboxes go here. Users are allowed to choose one option of a few you have given them.
</form>


Inside your action, you put the page that does insertion into your DB.

If this is unclear, please post your code.

rotten69 20 Posting Whiz

Once you have wamp server up and running, go to this URL "localhost/phpmyadmin" then Create a Database. Then inside the Database you created, You can create as many tables as you want.

if you still have any problems, just post them and we will try helping you.

I hope this helps you a bit :)

rotten69 20 Posting Whiz

@abelingaw: Thanks, mate..

rotten69 20 Posting Whiz

@ Cereal: Thanks buddy.

@simplypixie: You don't seem to have understood the Question. Unfortunately, the website you posted here does NOT include a PHP exercise at all. If it truly does, then just post a direct link to the exercises.

Cheers,

rotten69 20 Posting Whiz

Hi php geeks, I'm just looking for PHP exercise online. If anyone knows websites that offer hands-on PHP exercise, Please send me a link or something that redirects me to useful exercises.


Your help will be appreciated.


Cheers,

rotten69 20 Posting Whiz

Try to use the default username = root and default password if you havent changed it.

rotten69 20 Posting Whiz

IF you want to find more info about those keywords such as ON DUPLICATE, CASCADE, AFTER INSERT , BEFORE INSERT. You always refer to Oracle web site. There is so much info.

Good Luck. Please mark the thread as solved. Thanks.

rotten69 20 Posting Whiz

Or you can put a constraint on the field to restrict the input. In your case, you'd check if the input contains numbers, if yes. then it won't be inserted.

ALTER TABLE TableName ADD CONSTRAINT ConstraintName CHECK(YourField........  )

Instead of the dots up there, you replace them with a function or something that checks if the input is CHAR or is not INT.

rotten69 20 Posting Whiz

thanks, pal

rotten69 20 Posting Whiz
public static void main(String [] args){
		
		ArrayList<String> list1 = new ArrayList<String>();
		list1.add("ABC");
		list1.add("123");
		
		ArrayList<String> list2 = method(list1);
		list2.add("ABC");
		list1.add("123");
		System.out.println(list1);
		System.out.println(list2);
	}
		
	private static ArrayList<String> method(ArrayList<String> list) {
		ArrayList<String> result = list;
		result.remove("123");
		return result;
	}

Could anyone explain this code to me? why it gives me the same result in list1 & list2..


thank you,

rotten69 20 Posting Whiz

For my local db..

rotten69 20 Posting Whiz

Thanks buddy. Do you know if I need to pay anything for the username n password?

rotten69 20 Posting Whiz

I have installed SQLPlus on my ubuntu 10.10 and now I want to install Oracle server..
I was following a tutorial on that and at the end of it, I got lost because I don't have access to certain files that were mentioned in the tutorial and I changed permissions on the files. It didn't seem to work.


Does anyone know any good tutorials about how to install and configure Oracle server?

Do I have to have a username and password that are associated with Oracle? Or is it just like MySql? I can run locally..?

Cheers,

rotten69 20 Posting Whiz

Hey everyone,

Is this the right way how to make a trigger in Oracle?

CREATE OR REPLACE TRIGGER "TRI_AMOUNT_REDUCTION"
	      BEFORE INSERT ON "PURCHASE"
	      FOR EACH ROW
	    BEGIN
		IF (:NEW.CLIENTNO =SELECT C.CNAME, T.CLIENTNO, T.TOTAL FROM

                       CLIENT C, ( SELECT A.* FROM (SELECT CLIENTNO, SUM(AMOUNT)  AS 

TOTAL FROM PURCHASE GROUP BY CLIENTNO) A,(SELECT MAX(B.TOTAL) AS TOP FROM(SELECT 

CLIENTNO, SUM(AMOUNT) AS TOTAL FROM PURCHASE GROUP BY CLIENTNO)B)C 

WHERE A.TOTAL=C.TOP) T
WHERE C.CLIENTNO = T.CLIENTNO; ) THEN
			:NEW.AMOUNT := AMOUNT - (AMOUNT * 0.1);
		END IF;
	    END;
	    /

When I run this script, the server says "the trigger created with compilation errors"... I don't know what that exactly means

rotten69 20 Posting Whiz

Hey everyone,

I'm trying to count all Purchases and find ReceiptNo the ones that start with '434'..

Select count(p.purchaseNo) from purchase p (select  INSTR(TO_CHAR(p.recceiptNo), "434") >= 10;

But this line doesn't only select all receipt number starting with 434.. it selects all receipt no that has 434 in it....


I need help with this please

rotten69 20 Posting Whiz

Thanks, buddy..

rotten69 20 Posting Whiz

Can anyone see anything wrong with this statement?

CREATE OR REPLACE VIEW V_DEPT_AMOUNT AS       
	      SELECT DEPTNO AS DNO, DNAME AS DNAME, MAX(AMOUNT) AS  MAX_AMOUNT, 
              AVG(AMOUNT) AS AVG_AMOUNT, MIN(AMOUNT) AS MIN_AMOUNT, 
              SUM(AMOUNT) AS  TOTAL_AMOUNT FROM DEPT D, EMP E, PURCHASE P
              WHERE D.DEPTNO = E.DEPTNO
	      GROUP BY DNAME, DEPTNO;

It is meant to list names and numbers of all company departments together with the maximum, minimum, average and total amount contributed by each department.


The error I am getting is that "column ambiguously defined"

rotten69 20 Posting Whiz

thanks guys for all pieces of advice you've given me ...

rotten69 20 Posting Whiz

hey everyone,

I'm trying to get my head around this Question but it is not making that much sense ..


Each receipt is issued from a receipt book whose number is encoded in the first
three digits of the ReceiptNo field in the PURCHASE table. For example, the
receipt numbered 454333 was issued from receipt book number 454.
Write a SQL statement to count the number of purchases for which there has been at
least 10 other purchases issued from the same receipt book.

Hint: for each purchase p in the PURCHASE table, you will need to go over all
the other purchases and find the ones with a ReceiptNo that starts with the same
3 digits as in p’s ReceiptNo.


The only way I'm thinking about to solve this is to go with a function-based index.. Is there any other way of solving it?

I know how to write a SQL statement that counts how many purchases but I'm not too sure what to put in the where clause.. .


Hear from you folks...

rotten69 20 Posting Whiz

Good practice is to have something like this in mind.. If you're dealing with DB systems, connection_name.open at the top and once all queries and things are done with the DB then close it... connection_name.close

please check the php manual site for more info on how to open/close connection.. php.net

rotten69 20 Posting Whiz

Hey everyone,

I have been looking for video tutorials on SWING class and pretty much of GUI side in Java .. I found tutorials on Oracle site but they require lots and lots of reading..

if anyone knows a good site that has videos on GUI, please share it..

Time == issue then look for something easy to follow

Cheers,

rotten69 20 Posting Whiz

True.. I may have new clients coming into the system in the future. As specified in my current trigger, the top client is a guy with ClientNo = 122336. However, he is NOT always a top client. I might have a new guy with ,let's say, ClientNo = 122338 and his purchases are higher than the previous guy's.

To get around this, I need to add my select statement to see who's my top client and if top client exists then give him/her a 10% reduction in price..

Does their "amount" still stay at a 10% premium, or do they get reduced by the previous 10%?

I ain't sure what happens if a new client replaces the old one.
Cheers,

cheers,