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

Явное - текст

public class HelloWorld{

     public static void main(String []args){
        System.out.println("40000"+"00000");
        
     }
}

Явное

public class HelloWorld{

     public static void main(String []args){
        System.out.println("2000000000"+"2000000000")
        
     }
}

Compile and Execute Java Online

class A extends Thread
{
    public void run()
    {
        for(int i=0;i<=5;i++)
        {
            System.out.println("from a:"+i);
        }
        System.out.println("exit from a");
    }
}
class B extends Thread
{
    public void run()
    {
        for(int j=0;j<=5;j++)
        {
            System.out.println("from b:"+j);
        }
        System.out.println("exit from b");
    }
}
class C extends Thread
{
    public void run()
    {
        for(int k=0;k<=5;k++)
        {
            System.out.println("from c:"+k);
        }
        System.out.println("exit from c");
    }
}
public class Multithreads
{
    public static void main(String[] args)
    {
        
        new A().start();
        new B().start();
        new C().start();
    }
}

qwer

class ThreadDemo extends Thread {
   private Thread t;
   private String threadName;
   
   ThreadDemo( String name) {
      threadName = name;
      System.out.println("Creating " +  threadName );
   }
   
   public void run() {
      System.out.println("Running " +  threadName );
     
         for(int i = 4; i > 0; i--) {
            System.out.println("Thread: " + threadName + ", " + i);
            // Let the thread sleep for a while.
        
         }
      
      System.out.println("Thread " +  threadName + " exiting.");
   }
   
   public void start (int i) {
      System.out.println("Starting " +  threadName );
      if (t == null) {
          if(i==1){
         t = new Thread (this, threadName);
         t.setPriority(10);
         t.start ();
          }
          else{
               t = new Thread (this, threadName);
                      t.setPriority(2);
         t.start (); 
          }
      }
   }
}

public class TestThread {

   public static void main(String args[]) {
      ThreadDemo T1 = new ThreadDemo( "Thread-1");
      T1.start(1);
      
      ThreadDemo T2 = new ThreadDemo( "Thread-2");
      T2.start(2);
   }   
}

1234

public class HelloWorld{

     public static void main(String []args){
        int a = 1;
        int b = 2;
        
        System.out.println("a = " + a + "\nb = " + b);
        
        
        
        System.out.println("a = " + a + "\nb = " + b);
     }
}

Compile and Execute Java Online

public class HelloWorld{

     public static void main(String []args){
         int day=1;
         if (day==12)
         System.out.println("Monday");
         else if (day==2)
         System.out.println("tuesday");
          else if (day==3)
         System.out.println("Wednesday");
          else if (day==4)
         System.out.println("Thursday");
          else if (day==5)
         System.out.println("Friday");
          else if (day==6)
         System.out.println("Saturday");
          else if (day==7)
         System.out.println("Sunday");
         else 
        System.out.println("Enter a valid number");
     }
}

Generator

import java.util.ArrayList;

class sigmaStar {

    int length = 0;

    ArrayList<ArrayList<Integer>> setForLength;

    int iteration = 0;

    void powerSet() {

        setForLength = new ArrayList<ArrayList<Integer>>();

        ArrayList<Integer> originalArray = new ArrayList<>();

        setForLength.add(new ArrayList<Integer>());

        for(int i = 0; i < length; i++) {
            originalArray.add(i);
        }
        powerSetHelper(new ArrayList<Integer>(), originalArray, 0);
    }

    void powerSetHelper(ArrayList<Integer> array, ArrayList<Integer> originalArray, int index) {
        int i = index;

        while(i < originalArray.size()) {

            ArrayList<Integer> temp = copy(array);

            temp.add(originalArray.get(i));

            setForLength.add(temp);

            i++;

            powerSetHelper(temp, originalArray, i);
        }
    }


    //to make a deep copy
    ArrayList<Integer> copy(ArrayList<Integer> arrayToBeCopied) {

        ArrayList<Integer> copiedArray = new ArrayList<>();

        for(int value : arrayToBeCopied) {
            copiedArray.add(value);
        }
        return copiedArray;
    }


    String next () {

        String x1 = "";
        //when we move onto the strings of a length one greater than the previous string
        if (iteration == 0) {
            powerSet();
        }

        for(int i = 0; i < length; i++) {
            if(setForLength.get(iteration).contains(i)) {
                x1 += "b";
            }
            else {
                x1 += "a";
            }
        }

        iteration++;

        if (iteration == Math.pow(2, length) || length == 0) {
            length++;
            iteration = 0;
        }

        return x1;
    }


}


public class Main {

    public static void main(String[] args) {
        sigmaStar s = new sigmaStar();
        for(int i = 0; i < 220; i++) {
            System.out.println("STRING " + (i + 1) + " : " + s.next());
            
        }

    }
}

test

import java.util.Scanner;

public class QuadraticEquationSolver{
 public static void main(String[] args){
  
   Scanner input = new Scanner(System.in);

//getting variables for equation from user   
   System.out.println("print in a value for a variable");
   int a;
   a = input.nextInt();
   
   System.out.println("print in a variable for b value");
   int b;
   b = input.nextInt();
   
   System.out.println("print in a variable for c value");
   int c;
   c = input.nextInt();
   
   //finding roots
   
   double part1 = Math.sqrt(b*b - 4 * a * c);
   
   double root1 = (-b + part1)/(2 * a);
   double root2 = (-b - part1)/(2 * a);
   
 System.out.println("the roots of the quadratic equation are" + root1 + "and" + root2);
        
    
        
     }
}

Compile and Execute Java Online

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;
import java.util.List;



public class HelloWorld{
     Double litre = 0D;
     Double duree = 0D;
     int litres = 0;
     private static final Double URBAIN = 3D;
     private static final Double MIXTE = 6D;
     private static final Double AUTOROUTE = 8D;
     private static final int VMIN = 40;
     private static final int VMAX = 110;
     private static final int KMMIN = 30;
     private static final int KMMAX = 60;
     private static final int INCLMIN = -5;
     private static final int INCLMAX = 10;
     
     public static void main(String []args){
        HelloWorld hl = new HelloWorld();
        hl.run();
     }
     
     public void run(){
        
        String str = "5\n9\n37 61 -1 0;35 59 10 1;50 107 -5 1;48 105 9 0;56 50 9 0;49 100 7 0;55 106 3 1;40 49 6 0;\n46 96 9 0;47 101 4 1;34 51 0 1;52 86 9 0;30 60 9 0;54 90 -1 0;40 56 1 1;\n45 99 1 1;41 101 5 0;36 89 -5 0;33 77 -4 0;30 96 -2 1;53 94 2 1;53 79 -1 0;\n31 90 6 1;43 83 -5 0;30 105 7 0;55 91 -4 1;45 106 7 0;44 80 10 1;\n54 61 -4 0;59 48 9 1;36 94 4 1;50 70 -5 1;30 49 9 1;42 52 -1 1;\n59 104 0 0;59 106 1 0;31 62 7 0;49 100 7 1;33 44 -3 0;54 43 5 1;59 72 -4 1;50 60 5 1;\n33 83 -1 0;59 102 0 0;57 96 9 1;39 103 2 1;39 53 2 0;44 58 0 1;\n35 64 -1 0;54 110 -4 0;37 99 2 1;54 80 -1 0;50 109 -1 1;37 100 6 0;38 104 5 0;\n59 86 3 1;49 42 5 0;47 91 -5 1;56 54 6 0;50 100 -5 1;51 109 -2 0;\n44 71 4 1;58 100 -1 0;56 56 -4 0;42 57 3 1;41 73 -2 1;49 43 -5 0;";
        List<String> list = new ArrayList<String>(Arrays.asList(str.split("\n")));
        int i = 0;
        
        int reponse = -1;
        Double dureeRep = 0D;
        ArrayList<ArrayList<ArrayList<Integer>>> listFinal = new ArrayList<ArrayList<ArrayList<Integer>>>();
        for(String st : list){
            if(i==1){
                litres = Integer.parseInt(st);
            }else if(i>1){
                 List<String> listPortion = new ArrayList<String>(Arrays.asList(st.split(";")));
                 listFinal.add(new ArrayList<ArrayList<Integer>>());
                 int j = 0;
                 for(String sta : listPortion){
                     List<String> listRoute = new ArrayList<String>(Arrays.asList(sta.split(" ")));
                    listFinal.get(i-2).add(new ArrayList<Integer>());
                    for(String stb : listRoute){
                         listFinal.get(i-2).get(j).add(Integer.parseInt(stb));
                    }
                    j++;
                 }
            }
            i++; 
        }
        this.calculateBestLine(listFinal);

        
        //ArrayList<ArrayList<ArrayList<Integer>>> array = this.generate();
        //ArrayList<ArrayList<ArrayList<Integer>>> array = listFinal;
        //this.printValues(array);
       // this.calculateLines(array);
        
        
     }
     

     public void calculate(ArrayList<Integer> val){
         Double km = Double.valueOf(val.get(0));
         Double vitesse = Double.valueOf(val.get(1));
         Double incl = Double.valueOf(val.get(2));
         Double virage = Double.valueOf(val.get(3));
         Double conso;
         
         if(virage.equals(1D)){
             vitesse-=20D;
         }
         
         if(vitesse <= 49D){
             conso = URBAIN;
         }else if(vitesse >= 50D && vitesse <= 89){
             conso = MIXTE;
         }else{
             conso = AUTOROUTE;
         }
         
         if(incl<0D){
             conso = 0D;
         }else{
             conso = conso*(1D + incl/100D);
         }
         
        
         
         duree += km/vitesse;
         litre += (km/100D)*conso;
         
        
         
     }
     
    public int randInt(int min, int max) {
        Random rand = new Random();
        int randomNum = rand.nextInt((max - min) + 1) + min;

        return randomNum;
    }
    
    public ArrayList<ArrayList<ArrayList<Integer>>> generate(){
         ArrayList<ArrayList<ArrayList<Integer>>> array = new ArrayList<ArrayList<ArrayList<Integer>>>();
         int j = 0;
         while(j < 10){
              int rand = randInt(6,8);
              int i = 0;
             array.add(new ArrayList<ArrayList<Integer>>()); 
             while(i < rand){
                 array.get(j).add(new ArrayList <Integer>());
                 array.get(j).get(i).add(randInt(KMMIN,KMMAX));
                 array.get(j).get(i).add(randInt(VMIN,VMAX));
                 array.get(j).get(i).add(randInt(INCLMIN,INCLMAX));
                 array.get(j).get(i).add(randInt(0,1));
                 i++;
             }
             j++;
         }
         return array;
     }
     
     
     public void printValues(ArrayList<ArrayList<ArrayList<Integer>>> array){
          for (ArrayList<ArrayList<Integer>> arraya : array) {
             String str = "";
             for (ArrayList<Integer> arraytmp : arraya) {
      for (Integer tmp : arraytmp) {
          str += " " + tmp;
         }
         str += ";";
      }
   System.out.println(str);
         }
         
     }
     
     public void calculateLines(ArrayList<ArrayList<ArrayList<Integer>>> array){
         System.out.println("-------RESULTATS------");
         int i = 0;
         for (ArrayList<ArrayList<Integer>> arraya : array) {
             i++;
             duree = 0D;
             litre = 0D;
             for (ArrayList<Integer> arraytmp : arraya) {
      this.calculate(arraytmp);
      }
      
  System.out.println(i + " - duree : " + duree.toString());
         System.out.println(i + " - litre : " + litre.toString());
         System.out.println("-----------------");
         }
     }
     
      public void calculateBestLine(ArrayList<ArrayList<ArrayList<Integer>>> array){
         int i = 0;
         Double dureeG = 0D;
         int reponse = -1;
         for (ArrayList<ArrayList<Integer>> arraya : array) {
             i++;
             duree = 0D;
             litre = 0D;
             for (ArrayList<Integer> arraytmp : arraya) {
                this.calculate(arraytmp);
            }
            if(litre<=litres){
                if(reponse == -1){
                    reponse = i;
                    dureeG = duree;
                }else if(duree<=dureeG){
                    reponse = i;
                    dureeG = duree;
                }
            
            }

         }
         System.out.println(reponse);
     }
    
     
}

Compile and Execute Java Online

import java.util.Scanner;
 
public class rr {
        
    public static void main(String args[]) throws Exception {
            Scanner s = new Scanner(System.in);
 
          int wtime[],btime[],rtime[], ct[],num,quantum,total, wt[];
 
          wtime = new int[10];
          btime = new int[10];
          rtime = new int[10];
          ct = new int[10];
          wt = new int[10];
 
System.out.print("Enter number of processes(MAX 10): ");
num = s.nextInt();
System.out.print("Enter burst time");
for(int i=0;i<num;i++) 
{ 
System.out.print("\nP["+(i+1)+"]: "); 
btime[i] = s.nextInt(); 
rtime[i] = btime[i]; 
wtime[i]=0; 
} 
System.out.print("\n\nEnter quantum: "); 
quantum = s.nextInt(); 
int rp = num; 
int i=0; 
int time=0; 
System.out.print("0"); 
wtime[0]=0; 
while(rp!=0) 
{ 
if(rtime[i]>quantum)
 {

   rtime[i]=rtime[i]-quantum;
   System.out.print(" | P["+(i+1)+"] | ");
   time+=quantum;
   System.out.print(time);
   
   }
 else if(rtime[i]<=quantum && rtime[i]>0)
 {

 time+=rtime[i];
  rtime[i]=rtime[i]-rtime[i];
  System.out.print(" | P["+(i+1)+"] | ");
  rp--;
  ct[i] = time;
System.out.print(time);

 }
 
i++;
if(i==num)
{
	i=0;
}
 
}

for(i=0 ; i<num ; i++)
{
	System.out.println("Turnaround time of process P["+(i+1)+"]: "+ct[i]);
	System.out.println("Waiting time of process P["+(i+1)+"]: "+(ct[i]-btime[i]));
}




 
 
        }
}

Previous 1 ... 3 4 5 6 7 8 9 ... 1691 Next
Advertisements
Loading...

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