Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Test

public class StringDemo {

   public static void main(String args[]) {
      char[] helloArray = { 'h', 'e', 'l', 'l', 'o', '.' };
      String helloString = new String(helloArray);  
      System.out.println( helloString );
   }
}

Compile and Execute Java Online

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class myClass {

	public static void main(String [] args) throws IOException {
        Path p = Paths.get("C:\\Users\\KalamLocal\\Desktop\\KT");
        File f = new File (p.toString());
        //System.out.println(f.list().length);
     // int i = f.list().length;
     // File Directory;
	//int noOfFiles = f.list().length;
        for (File file : f.listFiles()){
            int j=1;
             DateFormat dateFormat = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");
     
  String fileName = new SimpleDateFormat("yyyyMMddHHmm'.txt'").format(new Date());
             File appendfile = new File(fileName);
//System.out.println("new file is created");
  FileWriter fr = new FileWriter(appendfile , true);
  BufferedWriter br = new BufferedWriter(fr);
        	System.out.println("ljlsjflsjljs");
       
        if (file.isDirectory()) {
        	if (file.list().length>0){

        		System.out.println("file is not empty");
        		File[] listOfFiles = file.listFiles();
        		for (int i = 0; i < listOfFiles.length; i++) {
        			System.out.println("File " + listOfFiles[i].getName());
   //System.out.println(listOfFiles[i].length());
   long inkb = listOfFiles[i].length() / 1024;
   long inmb = inkb /1024;
   String size = Long.toString(inmb);
   //System.out.println(inkb);
   //System.out.println(inmb);
 
  // SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
  //System.out.println("after format date is " + sdf.format(listOfFiles[i].lastModified()));
   //String strDate = sdf.format(sdf.format(listOfFiles[i].lastModified()));
   //String dateis = sdf.format(strDate);
  String strDate = dateFormat.format(listOfFiles[i].lastModified());
 
  br.write(String.format("%-20.20s" , listOfFiles[i].getName()));
  br.write("\t");
  br.write(String.format("%-15.15s", strDate));
  br.write("\t");
  br.write("\t");
  br.write(size);
  
  br.newLine();

  
  
  
        		}
        	}
        	else{
        		System.out.println("file is empty");
        		
        	}
        }
        br.newLine();
        br.write(j + "th Folder");
        br.newLine();
        br.newLine();
        br.close();
  fr.close();
        }
        	
	}
}

Compile and Execute Java Online

import java.util.*;

public class HelloWorld{
    
     private ArrayList<int> liste = new ArrayList<int>();
     
     public static void main(String []args){
        System.out.println("Hello World");
     }
}

Compile and Execute Java Online

public class HelloWorld{

     public static void main(String []args){
     int num1=70;
     int num2=50;
     int num3=40;
     if (num1>num2&&num1>num3){
         System.out.print(num1);
     }
     else if (num2>num1&&num2>num3){
         System.out.print(num2);
     }
     else if (num3>num2&&num3>num2){
         System.out.print(num3);
     }
     else{System.out.print("the no.s are equal");
     }
     
     
     }
}

largest of the three no.

public class HelloWorld{

     public static void main(String []args){
        int num1 = 70;
        int num2 = 30;
        int num3 = 40;
        if (num1 > num2 && num1 > num3)
         System.out.println("num 1 is the largest ");
        else if 
             (num2 > num1 && num2 > num3)
         System.out.println("num 2 is the largest ");
        
        else if  (num3 > num1 && num3 > num2)
         System.out.println("num 3 is the largest ");
        
         
     }
     
}

Homework 5

public class Homework5 {
// return the desired value of numbers in brackets 
     public static void main(String []args){
         printNumbers(12);
         printNumbers(5);
     }
    public static void printNumbers(int n) {
       for(int i=1;i<=n; i++){
        System.out.print("[" + i + "] ");
       }
      System.out.println("");
     }
     
}

InsertionSort Example

import java.util.Arrays;

public class InsertionSort 
{ 
	void sort(int array[]) 
	{ 
		int l = array.length; 
		for (int i = 1; i < l; ++i) 
		    { 
			int val = array[i]; 
			int j = i - 1; 

			while (j >= 0 && array[j] > val) 
			    { 
				array[j + 1] = array[j]; 
				j = j - 1; 
			} 
			array[j + 1] = val; 
		} 
	} 

	public static void main(String args[]) 
	{ 
		int[] array1 = { 0, 9, 8, 7, 6, 5, 4, 3, 2, 1 }; 
        int[] array2 = { 9, 3, 8, 1, 6, 5, 2 }; 

        System.out.println(Arrays.toString(array1));
        System.out.println(Arrays.toString(array2));

		InsertionSort ob = new InsertionSort(); 
		ob.sort(array1); 
		ob.sort(array2); 
		
        System.out.println(Arrays.toString(array1));
        System.out.println(Arrays.toString(array2));
	} 
}

Compile and Execute Java Online

import java.util.Arrays;

public class InsertionSort 
{ 
	void sort(int array[]) 
	{ 
		int l = array.length; 
		for (int i = 1; i < l; ++i) 
		    { 
			int val = array[i]; 
			int j = i - 1; 

			while (j >= 0 && array[j] > val) 
			    { 
				array[j + 1] = array[j]; 
				j = j - 1; 
			} 
			array[j + 1] = val; 
		} 
	} 

	public static void main(String args[]) 
	{ 
		int[] array1 = { 0, 9, 8, 7, 6, 5, 4, 3, 2, 1 }; 

        System.out.println(Arrays.toString(array1));

		InsertionSort ob = new InsertionSort(); 
		ob.sort(array1); 
		
        System.out.println(Arrays.toString(array1));
	} 
}

Compile and Execute Java Online

public class CLass1{
    
    
    public static void main(String []args){
        
        int a =21;
        
        System.out.println(a);
        
        
        int passengers;
        passengers = 0;
        passengers = passengers + 2 - 2;
        passengers = passengers - 1;
        passengers = passengers + 7;
        
        
        System.out.println(passengers);
    
      int a2 = 2;
      int b2 = 3;
      int c2 = 4;

       System.out.println(a2+b2*c2);
       
       int a3 = 3;
        a3 = a3*4;
        a3 = a3 + 2;
        
        System.out.println(a3);

    }
}

Compile and Execute Java Online

public class HelloWorld{

     public static void main(String []args){
         
         int n = 100;
        System.out.println(n);
     }
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.