0% found this document useful (0 votes)
51 views

Java Tutorials

The document contains 10 tutorials on basic Java concepts like methods, variables, input/output, arithmetic operators, if/else statements, and more. The tutorials show code examples to demonstrate concepts like defining and calling methods, declaring and assigning variables, taking user input, performing calculations, and conditional logic. Key Java classes and methods like System.out, Scanner, and if/else are introduced through examples.

Uploaded by

Shahmeer Khan
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views

Java Tutorials

The document contains 10 tutorials on basic Java concepts like methods, variables, input/output, arithmetic operators, if/else statements, and more. The tutorials show code examples to demonstrate concepts like defining and calling methods, declaring and assigning variables, taking user input, performing calculations, and conditional logic. Key Java classes and methods like System.out, Scanner, and if/else are introduced through examples.

Uploaded by

Shahmeer Khan
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 5

tutorial 4:

class Main{

//method

//method header

public static void main(String[]args){

//method body

System.out.println("Hello Youtube");//println is a built in method

//System.out.println means=print line in the system

//method header and method body together create something called a method

tutorial 5:

class Main{

public static void main(String[]args){

//variable in java is pretty much like a placeholder for something else

//int, double, float are keywords

//double means working with a number but that number can have a decimal point as well

double tuna;//declaring a variable

//tuna is a variable name

tuna=5.28;//assigning a variable

//5.28 is the value of variable, = is assignment operator

System.out.print("I want");

System.out.print(tuna);

System.out.println(" movies");//after this move to the nextline because of println

//(println)when it get's to the end of printing it, it moves to the next line
System.out.print("apples");

tutorial 6:

//basics of how to get input from the keyboard

//WE NEED TO MAKES A VARiable that's gonna hold a value from the keyboard before we use it we need
to write scanner in main method

//Scanner(means we are going to use scanner) buck(variable name)=new Scanner(System.in);

//buck variable is whatever information is in the keyboard

//Scanner is already built in java

//the way to get the scanner is to import it

import java.util.Scanner;//used for getting the Scanner

class Main{

public static void main(String[]args){

Scanner buck=new Scanner(System.in); //System.in stands for system input

//input we have in the computer is the keyboard

//so whatever we type in for the keyboard hold in our buck variable

System.out.println(buck.nextLine());

//nexLine(), what this is going to do is allow you to pause and wait untill

//you get input from Scanner buck=new Scanner(System.in);

//buck is a scanner variable

//at output if i write hey now, then buck=hey now, whenever i print buck, hey now will be shown

//if we don't import the scanner, we can never use it

//what scanner does, it takes the information that user types in from their keyboard and stores in a
variable

tutorial 7:

import java.util.Scanner;

class Main{

public static void main(String[]args){

Scanner buck=new Scanner(System.in);

double fnum, snum, total;

System.out.println("ENter first num");

fnum=buck.nextDouble();

System.out.println("ENter second num");

snum=buck.nextDouble();

total=fnum+snum;

System.out.println(total);

double totall;

totall=buck.nextDouble()+buck.nextDouble();

System.out.println(totall);

tutorial 8:

int are whole numbers like 6,76 etc without decimal point.

Modulo or Remainder Operator returns the remainder of the two numbers after division. If you are
provided with two numbers, say A and B, A is the dividend and B is the divisor, A mod B is there a
remainder of the division of A and B. Modulo operator is an arithmetical operator which is denoted by
%.23-Feb-2022

Reading allows individuals to engage with diverse perspectives, ideas, and arguments, which can help
stimulate and develop critical thinking skills. It helps to build the capacity for logical reasoning, problem-
solving, and decision-making, making you more prepared to deal with unfamiliar situations.05-Dec-2022

How Does Reading Improve Critical Thinking? [10 Reasons]

import java.util.Scanner;

class Main{

public static void main(String[]args){

Scanner buck=new Scanner(System.in);

double girls, boys, people;

girls=7;

boys=3;

people=girls/boys;

System.out.println(people);

people=girls%boys;

System.out.println(people);

tutorial 9:

int tuna=5;

System.out.println(tuna++);

//first post increment will use this variable as 5 and then will change it to 6.

tutorial 10:

class Main{

public static void main(String[]args){

int test=6;
if(test < 9){

System.out.println("yes");

}else{

System.out.println("this is else");

tutorial 10:

class Main{

public static void main(String[]args){

int boy, girl;

boy=8;

girl=99;

if(boy>10&& girl<60){

System.out.println("you can enter");

else{

System.out.println("you can not enter");

You might also like