Task - Input-Output - Practice Problems #79
Replies: 51 comments
-
1Io.javaimport java.util.Scanner;
public class Io {
public static void main(String[] args)
{
int a,b;
Scanner sc=new Scanner(System.in);
System.out.print("Enter the value of a ");
a=Integer.parseInt(sc.nextLine());
System.out.print("Enter the value of b ");
b=Integer.parseInt(sc.nextLine());
int sum=a+b;
int prod=a*b;
System.out.println(String.format("The sum of %d and %d is %d\nThe product of %d and %d is %d",a,b,sum,a,b,prod));
sc.close();
}
}Output2rect.javaimport java.util.Scanner;
public class rect {
public static void main(String args[])
{
double len,brd,area;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the length");
len=Double.parseDouble(sc.nextLine());
System.out.println("Enter the breadth");
brd=Double.parseDouble(sc.nextLine());
area=len*brd;
System.out.println(String.format("The area of the rectange is %f",area));
sc.close();
}
}Output3stud.javaimport java.util.Scanner;
public class stud {
public static void main(String[] args)
{
int roll;
String name,foi;
Scanner sc=new Scanner(System.in);
System.out.print("Enter the name: ");
name=sc.nextLine();
System.out.print("Enter the rollno: ");
roll=Integer.parseInt(sc.nextLine());
System.out.print("Enter the field of interest: ");
foi=sc.nextLine();
System.out.println(String.format("Hey my name is %s and my roll number is %d. My field of interest is %s",name,roll,foi));
sc.close();
}
}Output4Square.javaimport java.util.Scanner;
public class square {
public static void main(String args[])
{
double area,side,pmtr;
Scanner sc=new Scanner(System.in);
System.out.print("Enter the side of the square ");
side=Double.parseDouble(sc.nextLine());
pmtr=4*side;
area=side*side;
System.out.println(String.format("The area of the square is %f \nThe perimeter of the square is %f",area,pmtr));
sc.close();
}
}Output5strio.javaimport java.util.Scanner;
public class strio {
public static void main(String[] args)
{
String a,b;
Scanner sc=new Scanner(System.in);
System.out.print("Enter the first String ");
a=sc.nextLine();
System.out.print("Enter the Second String ");
b=sc.nextLine();
System.out.print(String.format("%s %s",a,b));
sc.close();
}
}Output |
Beta Was this translation helpful? Give feedback.
-
INPUT-OUTPUT PRACTICE PROBLEMS1.Write a program to take two integers as input from the user. First, print their sum and then print their product.InputOutputDemo.javaimport java.util.Scanner;
public class InputOutputDemo
{
public static void main(String ar[]) {
Scanner sc=new Scanner(System.in);
System.out.println("ENTER a:");
int a=Integer.parseInt(sc.nextLine());
System.out.println("ENTER b:");
int b=Integer.parseInt(sc.nextLine());
System.out.println("sum of a and b = "+ (a+b));
System.out.println("product of a and b = "+ a*b);
sc.close();
}
}Output2.Take the length and breadth of a rectangle as double inputs from the user, and print the area of the rectangle.RectangleDemo.javaimport java.util.Scanner;
public class RectangleDemo
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("ENTER LENGTH:");
double l=Double.parseDouble(sc.nextLine());
System.out.println("ENTER BREADTH:");
double b=Double.parseDouble(sc.nextLine());
System.out.println("AREA OF A RECTANGLE = "+ l*b);
}
} Output3.Take name, roll number and field of interest from the user and print in the format below :"Hey, my name is xyz and my roll number is xyz. My field of interest are xyz." FormatDemo.javaimport java.util.Scanner;
public class FormatDemo
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("ENTER YOUR NAME:");
String name=sc.nextLine();
System.out.println("ENTER YOUR ROLL_NUMBER:");
int rollno=Integer.parseInt(sc.nextLine());
System.out.println("ENTER YOUR FIELD OF INTEREST:");
String interest=sc.nextLine();
System.out.println(String.format("Hey, my name is %s and my roll number is %d. My field of interest are %s", name,rollno,interest));
sc.close();
}
}Output4.Take the side of a square from the user and print the area and perimeter of it.SquareDemo.javaimport java.util.Scanner;
public class SquareDemo
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("ENTER SIDE:");
int a=Integer.parseInt(sc.nextLine());
System.out.println("AREA OF A SQUARE = "+ a*a +" sqr.units");
System.out.println("PERIMETER OF A SQUARE = "+ 4*a +" units");
sc.close();
}
} Output5.Take two different string inputs and print them in the same line.StringDemo.javaimport java.util.Scanner;
public class StringDemo
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("ENTER STRING 1:");
String a=sc.nextLine();
System.out.println("ENTER STRING 2:");
String b=sc.nextLine();
System.out.println(a+" "+ b);
sc.close();
}
}Output |
Beta Was this translation helpful? Give feedback.
-
1.Sum and Productimport java.util.Scanner;
public class Sum {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("enter two numbers::");
int a=Integer.parseInt(sc.nextLine());
int b=Integer.parseInt(sc.nextLine());
System.out.println("sum="+(a+b));
System.out.println("Product ="+(a*b));
sc.close();
}
}2.Area of Rectangleimport java.util.Scanner;
public class RectArea {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("enter Length and Breadth::");
double len=Double.parseDouble(sc.nextLine());
double bre=Double.parseDouble(sc.nextLine());
System.out.println("Area of Rectangle::"+(len*bre));
sc.close();
}
}3.Detailsimport java.util.Scanner;
public class Details {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.print("enter name::");
String name=sc.nextLine();
System.out.print("enter rollno::");
int rollo=Integer.parseInt(sc.nextLine());
System.out.print("enter Area of Interest::");
String areaIntrest=sc.nextLine();
System.out.printf("My name is %s and my rollo is %d and my area of Interest is %s ",name,rollo,areaIntrest);
sc.close();
}
}4.Area and Perimeter of Squareimport java.util.Scanner;
public class SquareArea {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.print("enter Side of Square::");
double side=Double.parseDouble(sc.nextLine());
System.out.println("Area of Square::"+(side*side));
System.out.println("Perimeter of Square::"+(4*side));
sc.close();
}
}5.Two input Stringsimport java.util.Scanner;
public class StringInput {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("enter Two Strings::");
String str1=sc.nextLine();
String str2=sc.nextLine();
System.out.printf("Two Strings::%s %s",str1,str2);
sc.close();
}
} |
Beta Was this translation helpful? Give feedback.
-
1.Sum and Product.import java.util.Scanner;
public class UserInputDemo{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.print("Enter Number 1: ");
int a=Integer.parseInt(sc.nextLine());
System.out.print("Enter Number 2: ");
int b=Integer.parseInt(sc.nextLine());
System.out.println("The sum of two numbers is: "+(a+b));
System.out.println("The product of two numbers is: "+(a*b));
sc.close();
}
}2.Area of the Rectangle.import java.util.Scanner;
public class Rectangle {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.print("Enter the Length of the Rectangle: ");
double l=Double.parseDouble(sc.nextLine());
System.out.print("Enter the Breadth of the Rectangle: ");
double b=Double.parseDouble(sc.nextLine());
System.out.println("The Area of the Rectangle is: "+(l*b));
sc.close();
}
}3.Personal Detailsimport java.util.Scanner;
public class PersonalDetails {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.print("Enter the name: ");
String name=sc.nextLine();
System.out.print("Enter the RollNo: ");
int rollNo=Integer.parseInt(sc.nextLine());
System.out.print("Enter the Field of Interest: ");
String areaOfItrst=sc.nextLine();
System.out.printf("Hey, my name is %s, my rollNo is %d, my AreaOfInterest is %s.",name,rollNo,areaOfItrst);
sc.close();
}
}4.Squareimport java.util.Scanner;
public class Square {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.print("Enter the side of a Square: ");
int a=Integer.parseInt(sc.nextLine());
System.out.println("Area of the Square: "+(a*a));
System.out.println("Perimeter of the Square: "+(4*a));
sc.close();
}
}5.String Concatimport java.util.Scanner;
public class StringConCat {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.print("Enter name1: ");
String name1=sc.nextLine();
System.out.print("Enter name2: ");
String name2=sc.nextLine();
System.out.printf("%s %s",name1,name2);
sc.close();
}
} |
Beta Was this translation helpful? Give feedback.
-
Practice Problems1import java.util.Scanner;
public class InputDemo{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number: ");
int a=sc.nextInt();
System.out.println("Enter the number: ");
int b=sc.nextInt();
int sum=a+b;
int product=a*b;
System.out.println("Sum of the two numbers is "+sum);
System.out.println("Product of the two numbers is "+product);
}
}2import java.util.Scanner;
public class RectDemo {
public static void main(String[] args) {
Scanner sc =new Scanner(System.in);
System.out.println("Enter the length:");
Double length=sc.nextDouble();
System.out.println("Enter the breadth:");
Double breadth=sc.nextDouble();
Double area=length*breadth;
System.out.println("Area of the rectangle is:"+area);
}
}3import java.util.Scanner;
public class PrintDemo {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("Enter the name: ");
String Name=sc.nextLine();
System.out.println("Enter the rollno:");
int Rollno=Integer.parseInt(sc.nextLine());
System.out.println("Enter your field of interest:");
String FOI = sc.nextLine();
System.out.println("Hey, my name is "+Name+" and my roll number is "+Rollno+" .My field of interest is "+FOI+".");
}
}4import java.util.Scanner;
public class SquareDemo{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("Enter the side of a Square:");
int Side = sc.nextInt();
int Area=Side*Side;
int Perimeter=4*Side;
System.out.println("Area of the square is "+Area);
System.out.println("Perimeter of the square is "+Perimeter);
}
}5import java.util.Scanner;
public class StringProblm {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("Enter the Inputs:");
String Str1=sc.nextLine();
String Str2=sc.nextLine();
System.out.println(Str1+" "+Str2);
}
} |
Beta Was this translation helpful? Give feedback.
-
1SumProdimport java.util.*;
public class SumProd{
public static void main(String [] args){
Scanner sc = new Scanner(System.in);
System.out.println("Enter a : ");
int a=sc.nextInt();
System.out.println("Enter b : ");
int b=sc.nextInt();
int c=a+b;
int d=a*b;
System.out.println("Sum of the values is :"+c);
System.out.println("Sum of the values is :"+d);
}
}2Rectangleimport java.util.*;
public class Rectangle{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("Enter Length : ");
double l = sc.nextDouble();
System.out.println("Enter Breadth : ");
double b = sc.nextDouble();
double area = l*b;
System.out.println("Area of the Rectangle : "+area);
}
}3Interestimport java.util.*;
public class Interest{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("Enter name : ");
String name = sc.nextLine();
System.out.println("Enter roll number : ");
int rollno = Integer.parseInt(sc.nextLine());
System.out.println("Enter field of interest : ");
String interest = sc.nextLine();
System.out.println("Hey, my name is "+name+" and my roll number is "+rollno+".My field of interest is "+interest);
}
}4Squareimport java.util.*;
public class Square{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("Enter the side of a square : ");
int a = sc.nextInt();
int area = a*a;
int perimeter = 4*a;
System.out.println("Area of the square : "+area);
System.out.println("Perimeter of the square : "+perimeter);
}
}5StringInpimport java.util.*;
public class StringInp{
public static void main(String[] arg){
Scanner sc = new Scanner(System.in);
System.out.println("Enter String1 : ");
String s1 = sc.nextLine();
System.out.println("Enter String2 : ");
String s2 = sc.nextLine();
System.out.println("Entered String is : "+s1+" "+s2);
}
} |
Beta Was this translation helpful? Give feedback.
-
1import java.util.Scanner;
/*Write a program to take two integers as input from the user. First, print their sum and then print their product.*/
public class SumProduct {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println(" Enter the number 1");
int num1 = sc.nextInt();
System.out.println(" Enter the number 2");
int num2 = sc.nextInt();
int sum = num1+num2;
int product = num1*num2;3
System.out.println("The Sum is\t"+sum);
System.out.println("The Product is\t"+product);
sc.close();
}
}2import java.util.Scanner;
/*Take the length and breadth of a rectangle as double inputs from the user, and print the area of the rectangle.
*/
class Rect{
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
System.out.println("Enter the lenght of the rectangle");
double length=sc.nextDouble();
System.out.println("Enter the breadth of the rectangle");
double breadth=sc.nextDouble();
double area=length*breadth;
System.out.println("Enter the area of the rectangle"+area+" of the rectangle");
}
} 3import java.util.Scanner;
/*Take name, roll number and field of interest from the user and print in the format below :
"Hey, my name is xyz and my roll number is xyz. My field of interest are xyz." */
class RollNo{
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
System.out.println("Enter roll number");
int rollno =Integer.parseInt(sc.nextLine());
System.out.println("Enter the name");
String name = sc.nextLine();
System.out.println("Enter the Field of interest");
String interest = sc.nextLine();
System.out.println("Hey my name is \t" +name + "\tand my roll numberis \t" + rollno+"\tMy Field of interest are \t" + interest);
}
}4import java.util.Scanner;
//Take the side of a square from the user and print the area and perimeter of it.
class Square{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int area,perimeter;
System.out.println("Enter the side of a square");
int side = Integer.parseInt(sc.nextLine());
area = side * side;
System.out.println("Enter the area of the square"+area);
perimeter = 4 * area;
System.out.println("Enter the perimeter of the square"+perimeter);
}
}5import java.util.Scanner;
class CoreJava{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the input 1");
String input1 = sc.nextLine();
System.out.println("Enter the input 1");
String input2 = sc.nextLine();
System.out.print(input1 + " " + input2);
}
} |
Beta Was this translation helpful? Give feedback.
-
|
1 Write a program to take two integers as input from the user. First, print their sum and then print their product. import java.util.Scanner;
public class InputOutput {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter two integers");
int a = Integer.parseInt(sc.nextLine());
int b = Integer.parseInt(sc.nextLine());
System.out.println("Sum of given two numbers: " + (a + b));
System.out.println("Product of given two numbers: " + (a * b));
sc.close();
}
}2 Take the length and breadth of a rectangle as double inputs from the user, and print the area of the rectangle. import java.util.Scanner;
public class InputOutput2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter length and breadth of rectangle");
double l = Double.parseDouble(sc.nextLine());
double b = Double.parseDouble(sc.nextLine());
System.out.println("Area of rectangle is " + (l * b));
sc.close();
}
}3 Take name, roll number and field of interest from the user and print in the format below : import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
public class InputOutput3 {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Scanner sc = new Scanner(System.in);
System.out.println("Enter name");
String name = br.readLine();
System.out.println("Enter roll number");
int rollnum = Integer.parseInt(sc.nextLine());
System.out.println("Enter field of interest");
String interest = br.readLine();
System.out.println("Hey, my name is " + name + " and my roll number is " + rollnum
+ ". My field of interest are " + interest);
}
}4 Take the side of a square from the user and print the area and perimeter of it. import java.util.Scanner;
public class InputOutput4 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter side of square");
int a = Integer.parseInt(sc.nextLine());
System.out.println("Area of square is " + a * a);
System.out.println("Perimeter of square is " + 4 * a);
sc.close();
}
}5 Take two different string inputs and print them in the same line. import java.util.Scanner;
public class InputOutput5 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter two strings");
String s1 = sc.nextLine();
String s2 = sc.nextLine();
System.out.println(s1 + " " + s2);
sc.close();
}
} |
Beta Was this translation helpful? Give feedback.
-
1public class Addition {
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
System.out.println("Enter num 1");
int a=scan.nextInt();
System.out.println("Enter num 2");
int b=scan.nextInt();
System.out.println(String.format("The result of a+b is %d", a+b));
System.out.println(String.format("The result of a*b is %d", a*b));
}
}2public class Rectangle
{
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
System.out.println("Enter length");
double a=scan.nextDouble();
System.out.println("Enter breadth");
double b=scan.nextDouble();
System.out.println("Area of rectangle : " + String.format("%.2f", a*b));
}
}3public class Details
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String name=sc.nextLine();
String interest=sc.nextLine();
int rollno=Integer.parseInt(sc.nextLine());
System.out.println("Hey, My name is "+name+ " and my rollno is "+rollno+"."+"My field of interest is "+interest);
}
}4public class Square
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter length:");
double length=sc.nextDouble();
System.out.println("Area of square : " + String.format("%.2f", length*length));
System.out.println("Perimeter of square : " + String.format("%.2f", 4*length));
}
}5public class Concatenation
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String name1=sc.nextLine();
String name2=sc.nextLine();
System.out.println(name1+" "+name2);
}
} |
Beta Was this translation helpful? Give feedback.
-
1import java.util.*;
public class SumOfInteger {
public static void main(String[] args) throws Exception {
Scanner obj = new Scanner(System.in);
System.out.println("Enter the first number");
int fstNumber = obj.nextInt();
System.out.println("Enter the second number");
int SecondNumber = obj.nextInt();
int SumOfNumbers = fstNumber + SecondNumber;
System.out.println("Sum of the two numbers: " + SumOfNumbers);
obj.close();
}
}2import java.util.*;
public class AreaOfRectanguler {
public static void main(String[] args) throws Exception {
Scanner obj = new Scanner(System.in);
System.out.println("Enter the length of rectangle");
double length = obj.nextDouble();
System.out.println("Enter the breadth of rectangle");
double breadth = obj.nextDouble();
double areaOfRectangle = length * breadth;
System.out.println("area of rectangle is:" + areaOfRectangle);
}
}3import java.util.*;
public class UserDetail {
public static void main(String[] args) throws Exception {
Scanner obj = new Scanner(System.in);
System.out.println("Enter your name:");
String name = obj.nextLine();
System.out.println("Enter your roll number:");
int rollNumber = obj.nextInt();
obj.nextLine();
System.out.println("Enter your field of interest:");
String myFieldOfInterest = obj.nextLine();
System.out.println("Hey, my name is" + name + "and my roll number is" + rollNumber
+ ". My field of interest are" + myFieldOfInterest + ".");
obj.close();
}
}4import java.util.*;
public class Square {
public static void main(String[] args) throws Exception {
Scanner obj = new Scanner(System.in);
System.out.println("Enter the side of the square");
int square = obj.nextInt();
double areaOfSquares = square * square;
double areaofPerimeter = 4 * square;
System.out.println("area of square:" + areaOfSquares + "\narea of perimeter:" + areaofPerimeter);
obj.close();
}
}5import java.util.*;
public class Concat {
public static void main(String[] args) {
Scanner obj = new Scanner(System.in);
System.out.println("Enter the first string");
String str = obj.next();
System.out.println("Enter the second string");
String str2 = obj.next();
String concat = str.concat(str2);
System.out.println("String concat:" + concat);
obj.close();
}
} |
Beta Was this translation helpful? Give feedback.
-
1import java.util.Scanner;
public class MainClass{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter First Integer value : ");
int var1 = Integer.parseInt(sc.nextLine());
System.out.print("Enter Second Integer value : ");
int var2 = Integer.parseInt(sc.nextLine());
System.out.println("Sum of two Integers "+(var1+var2));
System.out.println("product of two Integers "+(var1*var2));
}
}2import java.util.Scanner;
public class MainClass{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter width of rectangle in Double value : ");
double width = Double.parseDouble(sc.nextLine());
System.out.print("Enter breadth of rectangle in Double value : ");
double breadth = Double.parseDouble(sc.nextLine());
System.out.println("Area of rectangle : "+(width*breadth));
}
}3import java.util.Scanner;
public class MainClass{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter name : ");
String name = sc.nextLine();
System.out.print("Enter roll no in Integer : ");
int rollno = Integer.parseInt(sc.nextLine());
System.out.print("Enter field of Interest in String : ");
String fieldOfInterest = sc.nextLine();
String stringformat = String.format("Hey, my name is %s and my roll number is %d My field of interest are %s",name,rollno,fieldOfInterest);
System.out.println(stringformat);
}
}4import java.util.Scanner; 5import java.util.Scanner;
public class MainClass{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter String1 : ");
String value1 = sc.nextLine();
System.out.print("Enter String2 : ");
String value2 = sc.nextLine();
String value3 = value1 + " "+ value2;
System.out.println("two strings : "+value3);
}
} |
Beta Was this translation helpful? Give feedback.
-
Problem 1 - SumProductimport java.util.Scanner;
public class SumProduct {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter two numbers:");
int num1=Integer.parseInt(sc.nextLine());
int num2=Integer.parseInt(sc.nextLine());
System.out.println("The Sum is : "+(num1+num2));
System.out.println("The Product is : "+(num1*num2));
sc.close();
}
}Problem 2 - RectangleAreapublic class RectangleArea {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the length of the rectangle");
double length=sc.nextDouble();
System.out.println("Enter the braedth of the rectangle");
double breadth=sc.nextDouble();
System.out.println("\nArea of the rectangle : "+(length*breadth));
sc.close();
}
}Problem 3 - SelfIntroimport java.util.Scanner;
public class SelfIntro {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter your Name: ");
String name = sc.nextLine();
System.out.print("Enter your Rollno: ");
int rollno=Integer.parseInt(sc.nextLine());
System.out.print("Enter your Field of Interest: ");
String field = sc.nextLine();
System.out.println("\nHey,my name is "+name+" and my roll number is "+rollno+".My field of interest are "+field+".");
sc.close();
}
}Problem 4 - SquareOperationimport java.util.Scanner;
public class SquareOperation {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.print("Enter the side of a square: ");
float side=sc.nextFloat();
System.out.println("\nArea of the square: "+side*side);
System.out.println("Perimeter of the square: "+(4*side));
sc.close();
}
}Problem 5 - InputSampleimport java.util.Scanner;
public class StringInput {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter two strings: ");
String str1=sc.nextLine();
String str2=sc.nextLine();
System.out.println(str1.concat(" "+str2));
sc.close()
}
} |
Beta Was this translation helpful? Give feedback.
-
1import java.util.Scanner;
public class Calculations {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("Enter first Integer:");
int a=sc.nextInt();
System.out.println("Enter second Integer:");
int b=sc.nextInt();
int c=a+b;
int d=a*b;
System.out.println("The sum of two integer is:"+c);
System.out.println("The product of two integer is:"+d);
}
}2import java.util.Scanner;
public class AreaOfRectangle {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("Enter the length of the triangle");
double length=sc.nextDouble();
System.out.println("Enter the breadth of the triangle");
double breadth=sc.nextDouble();
double AreaOfRectangle=0.5*(length*breadth);
System.out.println("Area of Rectangle is:"+ AreaOfRectangle);
}
}3import java.util.Scanner;
public class MyDetails {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the name of the student");
String name=sc.nextLine();
System.out.println("Enter the rollnumber of the student");
int rollno=Integer.parseInt(sc.nextLine());
System.out.println("Enter the field of interest");
String field=sc.nextLine();
System.out.println("Mydetails");
sc.close();
System.out.println(String.format("Hey, my name is %s and my roll number is %d. My field of interest is %s",name,rollno,field));
}
}4import java.util.Scanner;
public class Square {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("Enter the area of the square");
int a=Integer.parseInt(sc.nextLine());
int AreaofSquare = a*a;
int PerimeterOfSquare =4*a;
System.out.println("AreaofSquare is: " + AreaofSquare);
System.out.println("Perimeter of Square is: " + PerimeterOfSquare);
}
}
5import java.util.Scanner;
public class MainClass {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("enter the firstname");
String firstname= sc.nextLine();
System.out.println("Enter the lastname:");
String lastname= sc.nextLine();
String Myname=firstname+" "+lastname;
System.out.println("Myname is "+ Myname);
}
} |
Beta Was this translation helpful? Give feedback.
-
1.import java.util.Scanner;
public class Discussion {
public static void main(String[] args) {
int x, y;
Scanner sc = new Scanner(System.in);
System.out.println("Enter Num1 :");
x = Integer.parseInt(sc.nextLine());
System.out.println("Enter Num2 :");
y = Integer.parseInt(sc.nextLine());
int res = x + y;
System.out.println("Sum :" + res);
int prod = x * y;
System.out.println("Product :" + prod);
sc.close();
}
}2.import java.util.Scanner;
public class Area {
public static void main(String[] args) {
double x, y;
Scanner sc = new Scanner(System.in);
System.out.println("Enter length :");
x = Double.parseDouble(sc.nextLine());
System.out.println("Enter breadth :");
y = Double.parseDouble(sc.nextLine());
double area = x * y;
System.out.println("Area :" + area);
sc.close();
}
}3.import java.util.Scanner;
public class Userdata {
public static void main(String[] args) {
String name;
int rollNo;
String field_of_interest;
Scanner sc = new Scanner(System.in);
System.out.println("Enter Name :");
name = sc.nextLine();
System.out.println("Enter roll no. :");
rollNo = Integer.parseInt(sc.nextLine());
System.out.println("Enter roll no. :");
System.out.println("Enter field of interest :");
field_of_interest = sc.nextLine();
System.out.println("Hey, my name is " + name + "and my roll number is " + rollNo + ". My field of interest are "
+ field_of_interest);
sc.close();
}
} |
Beta Was this translation helpful? Give feedback.
-
import java.util.Scanner;
public class d79 {
public static void main(String[] args) {
Scanner obj = new Scanner(System.in);
System.out.println("Enter num1");
int a = obj.nextInt();
System.out.println("Enter num2");
int b = obj.nextInt();
int sum = a + b;
int product = a * b;
System.out.println("sum:" + sum);
System.out.println("product:" + product);
obj.close();
}
}screenshotimport java.util.Scanner;
public class d79b {
public static void main(String[] args) {
Scanner obj = new Scanner(System.in);
System.out.println("Enter the length of the rectangle");
double length = obj.nextDouble();
System.out.println("Enter the breadth of the rectangle");
double breadth = obj.nextDouble();
System.out.println("Area:" + length * breadth);
obj.close();
}
}screenshotimport java.util.Scanner;
public class d79c {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("ENTER NAME:");
String name = sc.nextLine();
System.out.println("ENTER ROLL_NUMBER:");
int rollno = Integer.parseInt(sc.nextLine());
System.out.println("ENTER FIELD OF INTEREST:");
String interest = sc.nextLine();
System.out.println(String.format("Hey, my name is %s and my roll number is %d. My field of interest are %s",
name, rollno, interest));
sc.close();
}
}screenshotimport java.util.Scanner;
public class d79d {
public static void main(String[] args) {
Scanner obj = new Scanner(System.in);
System.out.println("Enter the side of the square");
int side = obj.nextInt();
System.out.println("Area:" + side * side);
obj.close();
}
}screenshotimport java.util.Scanner;
public class d79e {
public static void main(String[] args) {
Scanner obj = new Scanner(System.in);
System.out.println("Enter the first string");
String s1 = obj.nextLine();
System.out.println("Enter the second string");
String s2 = obj.nextLine();
System.out.println("Output String:" + s1 + " " + s2);
obj.close();
}
}screenshot |
Beta Was this translation helpful? Give feedback.
-
code3public class Details {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("Enter Rollno");
int rollno = sc.nextInt();
System.out.println("Enter Name");
String name = sc.nextLine();
System.out.println("Enter Field of Interest");
String interest = sc.nextLine();
System.out.println("Hey my name is"+name+" and my roll no is "+rollno+"My field of interest is"+interest");
sc.close(); |
Beta Was this translation helpful? Give feedback.
-
Java3import java.util.Scanner; |
Beta Was this translation helpful? Give feedback.
-
code4public class Parameterofsquare{
public static void main(String [] args){
int a;
Scanner sc = new Scanner(System.in);
System.out.println("Enter length of side ");
a = sc.nextInt();
int parameter = a*4;
System.out.println("Parameter of square is" +parameter);
sc.close(); |
Beta Was this translation helpful? Give feedback.
-
Java4import java.util.Scanner; |
Beta Was this translation helpful? Give feedback.
-
code5import java.util.Scanner
public class Stringprogramm{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter first word);
String a = sc.next();
System.out.println("Enter second word);
String b = sc.next();
System.out.println(a.concat(b));
}
} |
Beta Was this translation helpful? Give feedback.
-
Java5import java.util.Scanner; Scanner in=new Scanner(System.in); |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Code2import java.util.Scanner;
public class A {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
double l = scan.nextDouble();
double b = scan.nextDouble();
System.out.println(l*b);
}
} |
Beta Was this translation helpful? Give feedback.
-
Code3import java.util.Scanner;
public class A {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter your name");
String name = scan.next();
System.out.println("Roll Number");
int roll = scan.nextInt();
System.out.println("Your Interest");
String interest = scan.next();
System.out.printf("Hey, my name is "+name+" and my roll number is "+roll+". My field of interest are "+interest);
}
} |
Beta Was this translation helpful? Give feedback.
-
IO2import java.util.Scanner; public class AreaRectangle { } 3import java.util.Scanner; } 4import java.util.Scanner; 5public class Print { } |
Beta Was this translation helpful? Give feedback.
-
Code4import java.util.Scanner;
public class A {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int side = scan.nextInt();
System.out.println(side*4);
}
} |
Beta Was this translation helpful? Give feedback.
-
Code2import java.util.Scanner;
public class A {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.println("enter two numbers");
double l = s.nextDouble();
double b = s.nextDouble();
System.out.println(l*b);
s.close();
}
} |
Beta Was this translation helpful? Give feedback.
-
Code3import java.util.Scanner;
public class Z {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("ENTER YOUR NAME:");
String name=sc.nextLine();
System.out.println("ENTER YOUR ROLL_NUMBER:");
int rollno=Integer.parseInt(sc.nextLine());
System.out.println("ENTER YOUR FIELD OF INTEREST:");
String interest=sc.nextLine();
System.out.println(String.format("Hey, my name is %s and my roll number is %d. My field of interest are %s", name,rollno,interest));
sc.close();
}
} |
Beta Was this translation helpful? Give feedback.
-
Code4import java.util.Scanner;
public class X {
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("ENTER SIDE:");
int a=Integer.parseInt(sc.nextLine());
System.out.println("AREA OF A SQUARE = "+ a*a);
System.out.println("PERIMETER OF A SQUARE = "+ 4*a);
sc.close();
}
} |
Beta Was this translation helpful? Give feedback.
-
Code5import java.util.Scanner;
public class Y {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("ENTER STRING 1:");
String a=sc.nextLine();
System.out.println("ENTER STRING 2:");
String b=sc.nextLine();
System.out.println(a+" "+ b);
sc.close();
}
} |
Beta Was this translation helpful? Give feedback.




















Uh oh!
There was an error while loading. Please reload this page.
-
Problem Statements
Write a program to take two integers as input from the user. First, print their sum and then print their product.
Take the length and breadth of a rectangle as
doubleinputs from the user, and print the area of the rectangle.Take name, roll number and field of interest from the user and print in the format below :
"Hey, my name is xyz and my roll number is xyz. My field of interest are xyz."
Take the side of a square from the user and print the area and perimeter of it.
Take two different string inputs and print them in the same line.
INPUT:
Core
Java
OUTPUT:
Core Java
Beta Was this translation helpful? Give feedback.
All reactions