r/learnjava • • Apr 18 '15

plz help me

Given 3 int values, a b c, return their sum. However, if one of the values is 13 then it does not count towards the sum and values to its right do not count. So for example, if b is 13, then both b and c do not count. Use the following template for writing your function: public int not13(int a, int b, int c){ } Expected Input: 1 2 3 Expected Output: 6

0 Upvotes

12 comments sorted by

4

u/Philboyd_Studge Apr 18 '15

How would you do this on paper?

2

u/BertRenolds Apr 18 '15

With a pencil, I hate writing in pen

2

u/Philboyd_Studge Apr 18 '15

Plz

2

u/BertRenolds Apr 18 '15

Sorry, I don't think OP is coming back

1

u/Philboyd_Studge Apr 19 '15

Halpplz

5

u/BertRenolds Apr 19 '15 edited Apr 19 '15

Finneee

public static int not13(int a, int b, int c){

	int[] myArray = {a,b,c};
	
	for (int i = 0 ; i>-1; i++){
		System.out.println("Op Plz");
	}
	
	return 6;

}

there it performs as desired, takes 3 integers in and returns 6

1

u/Philboyd_Studge Apr 19 '15

Incorrect. The method is supposed to be named not13

1

u/BertRenolds Apr 19 '15

There.

1

u/Philboyd_Studge Apr 19 '15

Your math checks out. OP, mark it solved!

2

u/quietnick Apr 18 '15

Put the values into an array.

Iterate over the values, if the value is 13, exit the array, else add the value.

-8

u/asna_nazar Apr 18 '15

plz solv it

4

u/BertRenolds Apr 18 '15

"learn java" if you want someone to do your homework, there is a sub for that