Take name, roll number and field of interest from user and print in the format below : Hey, my name is xyz and my roll number is xyz. My field of interest are xyz.
importjava.util.Scanner;classAns{publicstaticvoidmain(String[]args){Scanners=newScanner(System.in);System.out.println("Enter name");Stringa=s.next();System.out.println("Enter roll number");intb=s.nextInt();System.out.println("Enter Filed of interest");s.next();//To consume '\n' left by ENTER KEY, it is not consumed by nextInt()Stringc=s.nextLine();System.out.println("Hey, my name is "+a+" and my roll number is "+b+". My field of interest are "+c+".");}}
5.
Take side of a square from user and print area and perimeter of it.
Write a program to find square of a number. E.g.- INPUT : 2 OUTPUT : 4 INPUT : 5 OUTPUT : 25
7.
Take two different string input and print them in same line. E.g.- INPUT : Codes Dope OUTPUT : CodesDope
8.
Take 3 inputs from user and check : all are equal any of two are equal ( use && || )
importjava.util.Scanner;classAns{publicstaticvoidmain(String[]args){Scanners=newScanner(System.in);System.out.println("Enter first number");inta=s.nextInt();System.out.println("Enter second number");intb=s.nextInt();System.out.println("Enter third number");intc=s.nextInt();System.out.println("All are equal : "+(a==b&&b==c&&c==a));System.out.println("Any two are equal : "+(a==b||b==c||c==a));}}
9.
Write a program to enter the values of two variables 'a' and 'b' from keyboard and then check if both the conditions 'a < 50' and 'a < b' are true.
10.
If the marks of Robert in three subjects are entered through keyboard (each out of 100 ), write a program to calculate his total marks and percentage marks.