How to accept USER INPUT using Java! ⌨️

preview_player
Показать описание
#java #javatutorial #javacourse

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

if(isStudent){
}
else{
}

}
}
Рекомендации по теме
Комментарии
Автор

import java.util.Scanner;

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

Scanner scanner = new Scanner(System.in);

System.out.println("Enter your name: ");
String name = scanner.nextLine();

System.out.println("Enter your age: ");
int age = scanner.nextInt();

System.out.println("What is your gpa: ");
double gpa = scanner.nextDouble();

System.out.println("Are you a student? (true/false): ");
boolean isStudent = scanner.nextBoolean();

System.out.println("Hello " + name);
System.out.println("You are " + age + " years old");
System.out.println("Your gpa is: " + gpa);

if(isStudent){
System.out.println("You are enrolled in classes");
}
else{
System.out.println("You are NOT enrolled in classes");
}

scanner.close();
}
}

BroCodez
Автор

String name = "Bro Code";
int gta = 6;
double pi = 3.14159;
char gender = 'M';
boolean isAdmin = true;

icebot.
Автор

I personally like to use a BufferedReader over a Scanner

larsintech
Автор

import java.util.Scanner;

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

Scanner scanner = new Scanner(System.in);

System.out.print("what is your number: ");
int number = scanner.nextInt();
scanner.nextLine();

System.out.print("hello what is your namme : ");
String name = scanner.nextLine();

System.out.print("what is your cgpa: ");
double grade = scanner.nextDouble();

System.out.print("are you a student?: ");
boolean answer = scanner.nextBoolean();

System.out.println("my name is " + name);
System.out.println("my number is "+ number);
System.out.println("my cgpa is " + grade );

if(answer)
{
System.out.print("i am a student ");
}
else
{
System.out.print("i am not a student");
}
scanner.close();

}

}

clipsworld-sxpv
Автор

you can make ¹²³ with altGr and the numbers, is good to know if you not in win, cuz I use ubuntu and the num combinations never work for me (:

Doctor_Hinky
Автор

I tried to do the rectangle exercise, but after i enter width and height, the output of the area is always 0.0. I have no clue about how to solve this problem

giulioesposito
Автор

How did you short cut the System outprintln();?

nexograft
Автор

Why width, height and area=0
Can we run programme without putting them equal to zero???
I think thete is no need of width, height and area=0 at start

MubeenKhalid-iq
Автор

Today I went to a gloomy zoo.
In an exhibit, I saw a Joe Rogan.
Joe Rogan was muscular and vaping!
I was tired!

kylescritten
Автор

Mr Bo
I am ready this Java book and it have examples of entering data without a scanner
And I am not understanding that concept.
Here is the example

public static void main(String[] args) throws Exception {
double area, b, h;
 
//Data input - Prompt the user to enter values for base and height
System.out.print("Enter the length of base: ");
b =
System.out.print("Enter the length of height: ");
h =
 
//Data processing - Calculate the area of the rectangle
area = b * h;
 
//Results output - Display the result on user's screen
System.out.println("The area of the rectangle is " + area);
}

ihabmidhat
Автор

for some reason in the last part of the video, the code just breaks when i try to put in decimal numbers, it works when i put in full numbers, i copied everything exactly like in the video, my code is:
import java.util.Scanner;


public class Main {
public static void main(String[] args) {
double height = 0;
double width = 0;
double area = 0;

Scanner scanner = new Scanner(System.in);

System.out.print("enter the width: ");
width = scanner.nextDouble();

System.out.print("enter the height: ");
height = scanner.nextDouble();

scanner.close();
}
}
the error is:
Exception in thread "main"
at
at
at
at Main.main(Main.java:13)

Process finished with exit code 1
i tried it 3x in a new project and it still didnt work, im really confused why (i havnt slept last night, so might be something obvious, but im trying my best)
(it shouldnt matter that height and width are swapped in the thing where the values are assigned, right?)

GuruOfTheMoon
join shbcf.ru