Skip to main content

Posts

Showing posts from October, 2018

Five Java Programs asked in interview from Freshers

1. Write a program (WAP) to reverse a number or string. Source code: import java.util.Scanner; public class  ReString { public static void main(String[] args)  { Scanner sc = new Scanner(System.in); System.out.println("Enter a String:"); String str = sc.nextLine(); String ReStr=""; for(int i=str.length()-1;i>=0;i--) { ReStr = ReStr+str.charAt(i); } System.out.println("Reverse of String "+ str + " is " +ReStr); } } For Beginners To run: Firstly Save it with any name or  by Class name For example: ReString.java To Go to the Local disk or drive where you saved the programs(Open Command prompt) For example for E drive: e:  Then press: enter Now press cd folder name Finally For Compilation : javac filename.java (as shown in image ''javac ReString.java'') To execute : java classname (as shown in image 'java ReString'') Output: ...

Command shortcuts you may need. Try it.