Learn Java - Exercise 01x - Methods in Java

preview_player
Показать описание

Learn how to program in java with our online tutorial. We will cover variables, loops, if else branching, arrays, strings, objects, classes, object oriented programming, conditional statements, and more.

Here we get practice writing code that involve the use of methods in java.
Рекомендации по теме
Комментарии
Автор

I don't have any kind of method to return my "Gratitude" into your method.. It's all void.



UR THE BEST

saerey-KA
Автор

You can also switch case and call the methods from another class.

miracielmurillo
Автор

package Method;
import java.util.Scanner;
public class Methods {

public static void main(String[] args) {
int number =0;

System.out.println(" hi enter a number ");

Scanner input= new Scanner(System.in);

number= input.nextInt();

if (number==1) {
spring();}
else if ( number ==2 )
summer();
else if ( number ==3)
autum();
else if ( number == 4)
winter();
else System.out.println( " be sure the number from 1 to 4");

}


public static void spring() {
System.out.println( " it is spring");
}
public static void summer () {
System.out.println( " it is summer ");
}
public static void autum () {
System.out.println( " it is autum ");}
public static void winter ()
{
System.out.println( " it is winter ");}

}

myimmortal
Автор

you have made java interesting for me, just when i was almost giving up on it..can't seem to find anything on arrays. if you could please help with that as well... Bless up.

ogunmiluaabiodun
Автор

I am glad I tried the exercises first. I used method to write my code since we are learning about method. If anyone wants to see my code, I'll post it.

jeanjulmis
Автор

to every CS student checking the comments to see if this is worth watching









public static void printRecommendation(){

System.out.println("this is the best");


}

musasavage
Автор

Can i buy the whole volume in Blu-Ray?

raz
Автор

Another really helpful video! Thank you

fatimax
Автор

package lesson1;

import java.util.Scanner;

public class Lesson1Exercise {

public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int userInput;
System.out.println("Please enter a season of your choice.\n1 = Spring\n2 = Summer\n3 = Fall\n4 = Winter\n");

do {
userInput = input.nextInt();
switch(userInput) {
case 1: printSpring();
break;
case 2: printSummer();
break;
case 3: printFall();
break;
case 4: printWinter();
break;
default: System.err.println("Enter a seasonal number between 1-4: ");
break;
}
}while((userInput < 1) || (userInput > 4));
}

public static void printSpring() {
System.out.println("The season is Spring, and the flowers are blooming!");
}

public static void printSummer() {
System.out.println("The season is Summer, and it is getting hot!");
}

public static void printFall() {
System.out.println("The season is Fall, and leaves are falling!");
}

public static void printWinter() {
System.out.println("The season is Winter, and it is snowing!");
}

}

AONK
Автор

import java.util.Scanner;

public class JavaLearn {
public static void main(String[] args) {
Scanner sezoane = new Scanner(System.in);

int numar = 1;


System.out.println("Pentru fiecare sezon on parte scrie de la 1 la 4");
numar = sezoane.nextInt();

if (numar == 1) {
printPrimavara;

if (numar == 2) {
printVara();

if (numar == 3) {
printToamna();

if (numar == 4) {
printIarna();
}
public static void printPrimavara () {
System.out.println("Este primavara si este totul numai flori");
}
public static void printVara () {
System.out.println("Este vara si caldura este infernala");
}
public static void printToamna () {
System.out.println("Este toamna, iar frigul si frunzele se lasa");
}
public static void printIarna () {
System.out.println("A venit iarna si zapada este prezenta peste tot");
}
}

What is wrong here because does not work

andreirotaru.c
visit shbcf.ru