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

Compile and Execute Java Online

public class Person {
  private String name; // private = restricted access

  // Getter
  public String getName() {
    return name;
  }

  // Setter
  public void setName(String newName) {
    this.name = newName;
  }
}

Compile and Execute Java Online

public class MyClass {
  public static void main(String[] args) {
    Person myObj = new Person();
    myObj.name = "John";  // error
    System.out.println(myObj.name); // error  
  }
}

Compile and Execute Java Online

import java.util.Scanner;
public class TempConverter{
public static void main(String [] args)
{
    float f, c;
    f = c = 0;
    int a;
    Scanner scan = new Scanner (System.in);
    System.out.println("Press 1 for C->F or 2 for F->C");
    a = scan.nextInt();
    if (a == 1) 
        convertCtoFAndPrint();
    else
convertFtoCAndPrint();
}

public static void convertFtoCAndPrint()
{
    f = c = 0;
    Scanner scan = new Scanner (System.in);
    System.out.println("Please enter degrees F");
    f = scan.nextFloat();
    c = (5/9)*(f-32);
    System.out.println(f + " degrees F is " + c + " degrees C.");
}

public static void convertCtoFAndPrint()
{
    Scanner scan = new Scanner (System.in);
    System.out.println("Please enter degrees C");
    c = scan.nextFloat();
    f = c*(9/5)+32;
    System.out.println(c + " degrees C is " + f + " degrees F.");
}

}

Multichannel

import java.io.*;
import java.util.*;

public class Multichannel
{    public static void main(String a[])throws IOException
{BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
Random r=new Random(0);
int i,j;
int arrivaltime[]={1,2,3,4};
double arrivalprob[]={0.25,0.40,0.20,0.15};
double cumarrival[]=new double[arrivalprob.length];
int arrivalrda[]=new int[arrivalprob.length];
int ableservice[]={2,3,4,5};
double ableprob[]={0.30,0.28,0.25,0.17};
double cumable[]=new double[ableprob.length];
int ablerda[]=new int[arrivalprob.length];
int bakerservice[]={3,4,5,6};
double bakerprob[]={0.35,0.25,0.20,0.20};
double cumbaker[]=new double[bakerprob.length];
int bakerrda[]=new int[arrivalprob.length];
int randomarrival[]=new int[60/ableservice[0]];
int randomservice[]=new int[60/ableservice[0]];
int arrival[]=new int[60/ableservice[0]];
int service[]=new int[60/ableservice[0]];
int interarrival[]=new int[60/ableservice[0]];
int serviceable[]=new int[60/ableservice[0]];
int servicebaker[]=new int[60/ableservice[0]];
int ablestart[]=new int[60/ableservice[0]];
int bakerstart[]=new int[60/ableservice[0]];
int ableend[]=new int[60/ableservice[0]];
int bakerend[]=new int[60/ableservice[0]];
int ableprocess[]=new int [60/ableservice[0]];
int bakerprocess[]=new int[60/ableservice[0]];
int qtime[]=new int[60/ableservice[0]];
int ttime[]=new int[60/ableservice[0]];
int tempable=0,tempbaker=0;
float ableavgser=0,bakeravgser=0,waitingcust=0,ttq=0,tts=0;
for(i=0;i<cumarrival.length;i++)
{    if(i==0)
{    cumarrival[i]=arrivalprob[i];
arrivalrda[i]=(int)(cumarrival[i]*100d);
}

else
{    cumarrival[i]=cumarrival[i-1]+arrivalprob[i];
arrivalrda[i]=(int)(cumarrival[i]*100d);
}
}
for(i=0;i <cumable.length;i++)
{    if(i==0)
{    cumable[i]=ableprob[i];
ablerda[i]=(int)(cumable[i]*100d);
}
else
{    cumable[i]=cumable[i-1]+ableprob[i];
ablerda[i]=(int)(cumable[i]*100d);
}
}
for(i=0;i<cumbaker.length;i++)
{    if(i==0)
{    cumbaker[i]=bakerprob[i];
bakerrda[i]=(int)(cumbaker[i]*100d);
}
else
{    cumbaker[i]=cumbaker[i-1]+bakerprob[i];
bakerrda[i]=(int)(cumbaker[i]*100d);
}
}
randomservice[0]=(int)(Math.random()*100d);
for(i=1;i<(60/ableservice[0]);i++)
{    randomarrival[i]=(int)(Math.random()*100d);
randomservice[i]=(int)(Math.random()*100d);
}
for(i=1;i<(60/ableservice[0]);i++)
{    for(j=0;j<arrivalrda.length;j++)
{    if(randomarrival[i]==0)
{    arrival[i]=arrivaltime[arrivaltime.length-1];
break;
}
if(randomarrival[i]<=arrivalrda[j])
{    arrival[i]=arrivaltime[j];
break;
}
}
interarrival[i]=interarrival[i-1]+arrival[i];
}
for(i=0;i<(60/ableservice[0]);i++)
{    for(j=0;j<ablerda.length;j++)
{    if(randomservice[i]==0)
{    serviceable[i]=ableservice[ableservice.length-1];
break;
}
if(randomservice[i]<=ablerda[j])
{    serviceable[i]=ableservice[j];
break;
}
}
for(j=0;j<bakerrda.length;j++)
{    if(randomservice[i]==0)
{    servicebaker[i]=bakerservice[bakerservice.length-1];
break;
}
if(randomservice[i]<=bakerrda[j])
{    servicebaker[i]=bakerservice[j];
break;
}
}

}
for(i=0;i<(60/ableservice[0]);i++)
{    if(tempable<=interarrival[i])
{    ablestart[i]=interarrival[i];
ableend[i]=ablestart[i]+serviceable[i];
ableprocess[i]=serviceable[i];
tempable=ableend[i];
ttime[i]=ableprocess[i]+qtime[i];
}
else if(tempbaker<=interarrival[i])
{    bakerstart[i]=interarrival[i];
bakerend[i]=bakerstart[i]+servicebaker[i];
bakerprocess[i]=servicebaker[i];
tempbaker=bakerend[i];
ttime[i]=bakerprocess[i]+qtime[i];
}
else if(interarrival[i]> tempable)
{    ablestart[i]=tempable;
ableend[i]=ablestart[i]+serviceable[i];
ableprocess[i]=serviceable[i];
qtime[i]=tempable-interarrival[i];
tempable=ableend[i];
ttime[i]=ableprocess[i]+qtime[i];
waitingcust++;
}
else
{    bakerstart[i]=tempbaker;
bakerend[i]=bakerstart[i]+servicebaker[i];
bakerprocess[i]=servicebaker[i];
qtime[i]=tempbaker-interarrival[i];
tempbaker=bakerend[i];
ttime[i]=bakerprocess[i]+qtime[i];
waitingcust++;
}
}
for(i=0;(interarrival[i]<=60)&&(i<(60/ableservice[0]));i++)
{    ableavgser=ableavgser+ableprocess[i];
bakeravgser=bakeravgser+bakerprocess[i];
ttq=ttq+qtime[i];
tts=tts+ttime[i];
}
float totalcust=i;
System.out.println("No.\tRDA.\tARR.\tIARR.\tRDS.\tASTAT.\tAPRO.\tAEND.\tBSTAT.\tBPRO.\tBEND.\tTSQ.\tTIS");
System.out.println("-------------------------------------------------------------------------------------------------------");
for(i=0;(interarrival[i]<=60)&&(i<(60/ableservice[0]));i++)
{    System.out.println((i+1)+"\t"+randomarrival[i]+"\t"+arrival[i]+"\t"+interarrival[i]+"\t"+randomservice[i]+"\t"+ablestart[i]+"\t"+ableprocess[i]+"\t"+ableend[i]+"\t"+bakerstart[i]+"\t"+bakerprocess[i]+"\t"+bakerend[i]+"\t"+qtime[i]+"\t"+ttime[i]);
System.out.println("-------------------------------------------------------------------------------------------------------");
}
System.out.println("PERFORMANCE OF THE SYSTEM IS AS FOLLOWS:");
System.out.println("AVERAGE SERVICE TIME OF ABLE:"+(ableavgser/totalcust));
System.out.println("AVERAGE SERVICE TIME OF BAKER:"+(bakeravgser/totalcust));
if(waitingcust>0)
System.out.println("AVERAGE WAITING TIME OF THE CUSTOMER IS:"+(ttq/waitingcust));
System.out.println("PROBABILITY OF WAITING IS:"+(waitingcust/totalcust));
System.out.println("AVERAGE TIME SPENT BY CUSTOMER IN THE SYSTEM IS:"+(tts/totalcust));

}
}

nmnmm

public class HelloWorld{

     public static void main(String []args){
        System.out.println("Hello World");
     }
}

Compile and Execute Java Online

public class FinalReverseWithoutUsingStringMethod{
    
    

     public static void main(String []args){
         String str = "PAWAN";
         StringBuilder str2 = new StringBuilder();
         str2.append(str);
         str2=str2.reverse();
         System.out.println(str2);
        
     }
}

Compile and Execute Java Online

public class HelloWorld{

     public static void main(String []args){
        System.out.println("Hello World");
     }
}

X64mb

public class HelloWorld{

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

dmitryCalcTest1

import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {

        calcVer1("5+14");
    }

    private static void calcVer1(String input) throws Exception {
 

        Float number1 = 0F;
        String action = null;
        Float number2 = 0F;

        int dexaPart1 = 0;
        int dexaPart2 = 0;
        boolean isDotExsist = false;

        for (char symbol : input.toCharArray()) {

            if (symbol == '.') {
                isDotExsist = true;
            } else if (symbol == '/'
                    || symbol == '+'
                    || symbol == '-'
                    || symbol == '*') {
                action = String.valueOf(symbol);
                isDotExsist = false;
            } else if (Character.isDigit(symbol)) {
                Float digit = Float.valueOf(String.valueOf(symbol));
                if (action == null) {
                    if (isDotExsist) {
                        dexaPart1 = (int) (dexaPart1 * 10 + digit);

                    } else {
                        number1 = number1 * 10 + digit;
                    }
                } else {
                    if (isDotExsist) {
                        dexaPart2 = (int) (dexaPart2 * 10 + digit);

                    } else {
                        number2 = number2 * 10 + digit;
                    }
                }
            } else {
                throw new Exception("Не получилось");
            }
        }

        number1 = number1 + (float) (dexaPart1 / (Math.pow(10, String.valueOf(dexaPart1).length())));
        number2 = number2 + (float) (dexaPart2 / (Math.pow(10, String.valueOf(dexaPart2).length())));


        float result;
        switch (action) {
            case "+":
                result = number1 + number2;
                break;
            case "-":
                result = number1 - number2;
                break;
            case "*":
                result = number1 * number2;
                break;
            case "/":
                result = number1 / number2;
                break;
            default:
                System.out.println("Я пока не умею такую команду: " + action);
                return;
        }


        System.out.println(number1 + action + number2 + "=" + result);
    }


    private static void calcVer2() throws Exception {
        Scanner consoleReader = new Scanner(System.in);
        String input = consoleReader.next();

        Float number1 = 0F;
        String action = null;
        Float number2 = 0F;

        String buffer = "";
        for (char symbol : input.toCharArray()) {
            if (Character.isDigit(symbol) || symbol == '.') {
                buffer = buffer + symbol;
            } else if (symbol == '/'
                    || symbol == '+'
                    || symbol == '-'
                    || symbol == '*') {
                action = String.valueOf(symbol);
                number1 = Float.valueOf(buffer);
                buffer = "";
            } else {
                throw new Exception("Не получилось");
            }
        }

        number2 = Float.valueOf(buffer);

        float result;
        switch (action) {
            case "+":
                result = number1 + number2;
                break;
            case "-":
                result = number1 - number2;
                break;
            case "*":
                result = number1 * number2;
                break;
            case "/":
                result = number1 / number2;
                break;
            default:
                System.out.println("Я пока не умею такую команду: " + action);
                return;
        }


        System.out.println(number1 + action + number2 + "=" + result);
    }
}

Compile and Execute Java Online

public class HelloWorld
{

 public static void main(String []args)
 {
     


 for(int i=4; i>0; i--)//n=4
  {
     
   for(int j=0; j<=i; j++)
 
   {
   
     if(j<i)
   
     {
 
        System.out.print("_ ");

     }

     else
     {

        System.out.print(""+i);
 
     }
 
    }
 
     if(i<4)
    {
  
   for(int l=i; l<7-i; l++) //7-i=>(2n-1)-i           
      {
            
        System.out.print(" _");

       }

           System.out.print(" "+i);

        }
 
        for(int k=i; k>0; k--)

            {

             System.out.print(" _");
 
            }

            System.out.print("\n");
            
            if(i==1)
            {
                for(int a=i+1; a<=4; a++)//a=2
                {
                    for(int b=0; b<=a; b++) 
                 {
                      if(b<a)
   
                     {
 
                        System.out.print("_ ");

                     }

                      else
                     {

                        System.out.print(""+a);
 
                     }
 
                  }
                  System.out.print("\n");
                    
                 }
                
            }
            

      }
        

         
     }
}

Advertisements
Loading...

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