Video 5(ch1)

Yash
0


 Adding two numbers by taking input using integer-

https://drive.google.com/file/d/1_0f-HVBKPzEMjX9U8LKKTyxvFMY9mzD9/view?usp=drivesdk

import java.util.Scanner;


public class Main {

public static void main(String[] args) {

System.out.println("Taking input from the user");

Scanner sc = new Scanner (System.in);

System.out.println("Enter number 1:");

int a = sc.nextInt();

System.out.println("Enter number 2:");

int b = sc.nextInt();

int sum = a +b;

System.out.println("The sum of the numeber is :");

System.out.println(sum);

}

}


Adding two numbers by taking input using float-

https://drive.google.com/file/d/1_7xv8L_auRrbS5AF-EIS9wetR3zKRKXC/view?usp=drivesdk



import java.util.Scanner;


public class Main {

public static void main(String[] args) {

System.out.println("Taking input from the user");

Scanner sc = new Scanner (System.in);

System.out.println("Enter number 1:");

float a = sc.nextFloat();

System.out.println("Enter number 2:");

float b = sc.nextFloat();

float sum = a +b;

System.out.println("The sum of the numeber is :");

System.out.println(sum);

}

}


Checking the integer value :-

https://drive.google.com/file/d/1_9jP8_C6QgJPv4omAUqURAINGD6uly8F/view?usp=drivesdk



import java.util.Scanner;


public class Main {

 public static void main(String[] args) {

  Scanner sc = new Scanner (System.in);

     boolean b1=sc.hasNextInt();

     System.out.println(b1);

     //here if u enter the integer the value is true and if you enter the other values ln it gives false it because it check the input is integre or not .

 }

}


Printing word and line:-

https://drive.google.com/file/d/1_FojAyPCt2Y4Pfhn8z0odRaRlKXE26AW/view?usp=drivesdk



import java.util.Scanner;


public class Main {

public static void main(String[] args) {

Scanner sc = new Scanner (System.in);

//1// String str = sc.next();

//2

    String str =sc.nextLine();

System.out.println(str);

//the number 1 print only one after the space it will not print word whlie no.2 prints the whole line .

}

}


Video link:-https://youtu.be/HRfmLqqvzUs?si=D_bxGiGmQvf7V4Vs

Post a Comment

0 Comments
Post a Comment (0)
To Top