Computer Science, asked by swetaagarwal011, 11 months ago

how to write a java program
how to write a java program using scanner

Answers

Answered by animesh6219
4

Answer:

import java.util.Scanner;

class test{

public static void main( String a[])

{

Scanner sc=new Scanner (System.in);

int number = sc.nextInt();

String name= sc.next();

}

}

Answered by vageeshgn2005
1

Answer:

this is a simple scanner class program to find the sum of 2 number given by the user

PROGRAM:

import java.util.Scanner;//importing scanner class

public class number//class name

{

public static void main()//main method(String[] args statement in () is optional)

{

Scanner sc = new Scanner(System.in);//creating scanner object

int a,b;

System.out.println("Enter first number");//taking first number

a = sc.nextInt();//(convert string value to int value as scanner class takes string by default)

System.out.println("Enter second number");

b = sc.nextInt();

int c = a+b;//adding a and b values giver by the user

System.out.println("On adding"+a+" and "+b+" you get: "+c);//(the sum value)

}

}//end of program

Similar questions