Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,151,326 members, 7,811,965 topics. Date: Monday, 29 April 2024 at 02:42 AM

Java Tutorial: Beginner's Guild - Programming (2) - Nairaland

Nairaland Forum / Science/Technology / Programming / Java Tutorial: Beginner's Guild (3227 Views)

Which Programming Language Should A Beginner Start With? / How Would You Like A Java Tutorial Video In Pidgin / Get Web Programming, C++, Java Tutorial Tutorial Videos. (2) (3) (4)

(1) (2) (Reply) (Go Down)

Re: Java Tutorial: Beginner's Guild by Jas80: 3:05pm On Jan 18, 2020
Good afternoon, hope you all are fine?.....let's continue from were we stopped.
Let's look into the data types in java.
A simple interest program(formula is PRT/100)
public Simple interest{
public static void main(String [] arts){

int t=2;
Int r=10;
int p=11000;
double si=(p*r*t)/100;
System.out.println("the simple interest is:" + si);
}
}

Output: the simple interest is: 2200.0

1 Like

Re: Java Tutorial: Beginner's Guild by Jas80: 3:29pm On Jan 18, 2020
Pls note I am using my phone for the tutorial this afternoon, so pardon my typos, if any ( am telling u because of all this nairaland programmers).

Explanation of the code:

I told before that our variables must be assigned a data type. Our variables are p,r,t (which are the principal, rate and time respectively). And si(simple interest) which will hold our simple interest after calculation.

Note that the data type given to prt is the int data type. Remember that 2, 10 and 11000 are whole numbers. But our si is double because simple interest usually ends up with decimal numbers after calculations. We don't know what our answer will be, so we have to use the double data type if at all the answer will be a decimal number.

So, the data type u assign to a variable depends on the value of that variable. So if at all you know the answer for the simple interest above will be 2200, then you can assign the data type of "si" as int because 2200 is a whole number.

NOTE: there is something known as data type compatibility, don't assign data types anyhow

1 Like

Re: Java Tutorial: Beginner's Guild by Jas80: 3:54pm On Jan 18, 2020
Note that, Java is case sensitive, meaning that, Jas is different from jas, e is different from E, so check your variables
Re: Java Tutorial: Beginner's Guild by codedtony(m): 3:55pm On Jan 18, 2020
i need to learn java to be able to bind it with python for an android app
Re: Java Tutorial: Beginner's Guild by Jas80: 3:56pm On Jan 18, 2020
codedtony:
i need to learn java to be able to bind it with python for an android app

You don't need to bind it
Re: Java Tutorial: Beginner's Guild by codedtony(m): 4:00pm On Jan 18, 2020
[quote author=Jas80 post=85901303]

i do for the machine learning part of the project
Re: Java Tutorial: Beginner's Guild by Jas80: 4:07pm On Jan 18, 2020
[quote author=codedtony post=85901433][/quote]
Ok
Re: Java Tutorial: Beginner's Guild by Jas80: 9:46pm On Jan 19, 2020
Please I am looking for an apartment in ejigbo,canor-ajao axis mushin, reply this thread if you have any idea of who I can contact.,....abeg na better self contain o

1 Like

Re: Java Tutorial: Beginner's Guild by Jas80: 5:57pm On Apr 08, 2020
Hello guys, who is still interested in learning java, it has been a while

2 Likes

Re: Java Tutorial: Beginner's Guild by Pwaneido: 4:14pm On Apr 12, 2020
Jas80:
Hello guys, who is still interested in learning java, it has been a while
We are following keep it up
Re: Java Tutorial: Beginner's Guild by Jas80: 8:09pm On Apr 12, 2020
Good evening everyone, it has been a while. I have been too busy. For those of you who are still interested I will be continuing from were we stopped
Re: Java Tutorial: Beginner's Guild by Jas80: 8:23pm On Apr 12, 2020
So, in our last post, we talked about arithmetic operators, and we also wrote a simple interest program, using the arithmetic operators.

Today we are going to be be talking about logical operators. Logical operators are very useful operators you are going to need for your java programs. Below are some examples of logical operators.

The & Operator:
This operator checks two expression and returns true if both expressions are correct. For example, let's consider the program below.

public class Check {
public static void main (String args[]){

int a=20;
int b= 30;

System.out.println(a<b && b>20);
}
}

The output of the above program will be true. Because our variables a and b has the value of 20 and 30 respectively. from our expression, a<b, is correct because a =20 and b= 30, 20 is less than 30, so our first expression is true. Our second expression says b>20, this is also true because 30 is greater than 20. Hence, the output : true.

Note that, the && operator returns true only when both expression is true. Otherwise it returns false. That is to say that, it returns false when only one condition is true and returns false also when both expressions are false.
Re: Java Tutorial: Beginner's Guild by Jas80: 8:34pm On Apr 12, 2020
The || operator (or operator).

This operator returns true if both expressions or only one expression is true. It returns false only when both expressions are wrong.

For example.

public class Check {
public static void main (String args[]){

int a =20;
int b=15;

System.out.println(a>5 || b<10);
}
}

The output of the above code will be true. Because the first expression is true, a is 20, 20 is greater than 5, so this expression is correct. Our second expression is wrong because b is 15, and 15 is greater than 10.

Note, this operator is also called the or operator. It returns true if one of the expression is true, and returns false when both expressions are false
Re: Java Tutorial: Beginner's Guild by Jas80: 8:35pm On Apr 12, 2020
So, try the above codes and get back to me. That's all for now.

Ask your questions

1 Like

Re: Java Tutorial: Beginner's Guild by Nobody: 12:54am On Apr 13, 2020
Thanks we are following
Re: Java Tutorial: Beginner's Guild by AdolphBrian: 9:44am On Apr 13, 2020
I am also following
Re: Java Tutorial: Beginner's Guild by musa1010: 1:58am On Apr 14, 2020
carry on am following.
Re: Java Tutorial: Beginner's Guild by Jas80: 3:53pm On Apr 23, 2020
Good afternoon y'all

Last time we talked about the "and" and "or" operator, there are several other types of operators in programming. Maybe we will talk about some today.

Some words of wisdom before we start

The beauty about learning a programming language is that, you can use the experience you get from it to work with other programming languages. For example, all programming languages uses stuffs like loops, statements, arrays e.t.c

We all know all the advantages associated with being a programmer, so I advise you to never give up on the language even when you are finding it difficult to understand. All you have to do is, relax and come back at it with all you have got.

Let's go
Re: Java Tutorial: Beginner's Guild by Jas80: 4:04pm On Apr 23, 2020
Let's take a look at some other operators.

public class Example {

public static void main (String args []){

int a=20;
int b=30;

a+=b;

System.out.println(a);

}
}

The output of the above program will be:50.

How? The += operator add the value of the right hand expression to the initial value of the left hand side expression. From the program, initially, a was 20, and b =30. But from our program, we used the += operator. So, the value of be is added to the value of a


public class Example {

public static void main (String args []){

int a=20;
int b=30;

a-=b;

System.out.println(a);

}
}

The value of a will be -10.

public class Example {

public static void main (String args []){

int a=20;
int b=30;

a*=b;

System.out.println(a);

}
}
The value of a will be 600.

Hope you get the logic behind the programs above. Ask your questions

1 Like

Re: Java Tutorial: Beginner's Guild by Jas80: 4:10pm On Apr 23, 2020
Another important operator in java is the modulus operator (%). As you can see, this operator is represented using the percentage symbol.

This operator returns the remainder of a value after division.

For example, 5%4, will return 1, because 4 will go into 5 once, and the reminoder will be 1.

10% 6; will return 4, because 6 can go into 10 only once and the remainder will be 4. So, that is that for the modulus operator.


Exercise:
public class Example {

public static void main (String args []){

int a=5;
int b=3;

a%=b;

System.out.println(a);

}
}

Drop the answer below.
Re: Java Tutorial: Beginner's Guild by Jas80: 4:24pm On Apr 23, 2020
Waiting for your answers.

Another important concept in java is the if statement, if...else statement, if ....else if statement.

if statement

Basically, this statement is used to check whether an expression is correct or not. If the expression is correct it returns true but if the expression is wrong it returns false.

It is used to execute a statement if the expression is true.

For example.
public class Example {

public static void main (String args []){


int result=30;

if (result<50){

System.out.println("this student failed the exam"wink;
}
}
}

The output of the above program will be:this student failed the exam.

Explanation

From the above, the value of result is 30, and in our if statement, we asked if the value of result is less than 50, our program should display "this student failed the exam".

30 is lesser than 50, so this statement is correct, hence our expression will be executed.

Understand?
Re: Java Tutorial: Beginner's Guild by Jas80: 4:33pm On Apr 23, 2020
[b]If else statement

this statement has two options, one of the option is that our program should do this if the statement is correct, the other option is that our program should do something else, if the expression is not correct.


public class Example {

public static void main (String args []){


int result=30;

if (result<50){

System.out.print("student failed"wink;}
else{
System.out.print("student passed"wink;
}


}
}

Output: student failed

Let's try something else.

public class Example {

public static void main (String args []){


int result=70;

if (result<50){

System.out.print("student failed"wink;}
else{
System.out.print("student passed"wink;
}


}
}
Output: student passed

Hope you understood what happened

(1) (2) (Reply)

[Beginner Assistance] How Do I Start Programming? / Let's Build Your Mobile App Android/ios, Reliable, Affordable And Trusted / Correct This Registration Form Code Please!!!

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 35
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.