file_id
int64
1
250k
content
stringlengths
0
562k
repo
stringlengths
6
115
path
stringlengths
1
147
563
public class PrintW { public static void main(String[] args) { int height = 7; // You can change the height to any value you want for (int row = 0; row < height; row++) { for (int col = 0; col <= height * 2; col++) { // Print stars for the left and right sides, and the inner diagonals if (col == 0 || col == height * 2 || (row == col - height && row > height / 2) || (row + col == height * 2 && row > height / 2)) { System.out.print("*"); } else { System.out.print(" "); } } System.out.println(); } } }
venkatneelapu/java
W.java
564
import java.util.Scanner; public class s { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int Str=0; int in = 0; int dou = 0; // enter value for (int i = 0; i < a.length; i++) { a[i] = sc.next(); if(a[i]==0) } } }
akshatverma1/Java-Core
s.java
565
import java.util.*; import java.lang.*; import java.io.*; class Codechef { public static void main (String[] args) throws java.lang.Exception { // your code goes here Scanner sc=new Scanner(System.in); int T=sc.nextInt(); for(int i=0;i<T;i++) { int X=sc.nextInt(); int Y=sc.nextInt(); System.out.println(X-Y); } } }
kavyakonda2003/Programs
n.java
566
import java.awt.Canvas; import java.awt.Color; import java.awt.Graphics; import javax.swing.JFrame; import javax.swing.WindowConstants; public class C extends Canvas { private static final long serialVersionUID = 1480902466428347458L; private static final int WIDTH = 400; private static final int HEIGHT = 400; private static final int RANGE = 30; private static final int INTERVAL = 5; private double[][] values = new double[WIDTH][HEIGHT]; private double inertia = 0.8; private double decay = 0.9995; private double dissipation = 0.92; @Override public void paint(Graphics g) { super.paint(g); // Initialize all pixels as blank for (int x = 0; x < WIDTH; x++) { for (int y = 0; y < HEIGHT; y++) { values[x][y] = 0.0; g.setColor(color(values[x][y])); g.drawLine(x, y, x, y); } } // Store co-ordinates of last rain-drop and time since falling int lastX = -1; int lastY = -1; int lastT = -1; while (true) { // ~20ms per step (i.e. 50/sec) try { Thread.sleep(20); } catch (InterruptedException e) { e.printStackTrace(); } // With some probability, add a rain-drop on a random location and initialize the timer // Probability of rain-drop, should yield < 50/INTERVAL drops per second if (Math.random() < 1.0/INTERVAL) { lastX = (int) (Math.random() * WIDTH); lastY = (int) (Math.random() * HEIGHT); lastT = 0; } // Currently, simulate water inflow at last location for three time-steps // After, simply move drop off-canvas for simplicity else if (lastT >= 3) { lastX = -100; } lastT++; // Compute updated values at each point in time double[][] newValues = computeNewValues(lastX, lastY); // Draw new canvas for (int x = 0; x < WIDTH; x++) { for (int y = 0; y < HEIGHT; y++) { g.setColor(color(values[x][y])); g.drawLine(x, y, x, y); } } values = newValues; } } /* * Computes updated values given current state of canvas and last rain-drop */ private double[][] computeNewValues(int lastX, int lastY) { double[][] newValues = new double[WIDTH][HEIGHT]; // For each pixel (somewhat inefficient, but fine for small canvas) for (int i = 0; i < WIDTH; i++) { for (int j = 0; j < HEIGHT; j++) { double value = 0.0; int count = 0; // Compute distance to previous drop and if exist, simulate water inflow there double dist = Math.sqrt(Math.pow(Math.abs(i - lastX), 2) + Math.pow(Math.abs(j - lastY), 2)); if (dist < RANGE) { // Adjust new value by distance from drop ... double newValue = 1.0; while (dist-- > 0) newValue *= dissipation; // ... but make sure not to "destroy" water that's already there newValue = Math.max(newValue, values[i][j]); // Update new value using inertia from old value value = inertia * values[i][j] + (1 - inertia) * newValue; } // If not near new drop, simply simulate diffusion of water else { for (int x = i - 5; x <= i + 5; x++) { for (int y = j - 5; y <= j + 5; y++) { if (x < 0 || y < 0 || x >= WIDTH || y >= HEIGHT) continue; value += values[x][y]; count++; } } value /= count; } // Decay values to simulate water soaking into ground newValues[i][j] = value * decay; } } return newValues; } private float fromValue(double value) { return (float) (((300 * (1.0 - value) + 300) % 360) / 360.0); } private Color color(double value) { return Color.getHSBColor(fromValue(value), 1.0f, .5f); } public static void main(String[] args) { JFrame frame = new JFrame(); frame.setSize(WIDTH, HEIGHT); frame.add(new C()); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.setVisible(true); } }
rmshree/ECS189E
C.java
567
//{ Driver Code Starts //Initial Template for Java /*package whatever //do not write package name here */ import java.io.*; import java.util.*; class GFG { public static void main (String[] args) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int testcases = Integer.parseInt(br.readLine()); while(testcases-- > 0){ String line1 = br.readLine(); String []element = line1.trim().split(" "); int n = Integer.parseInt(element[0]); int l = Integer.parseInt(element[1]); int r = Integer.parseInt(element[2]); int arr[] = new int[n]; String line = br.readLine(); String[] elements = line.trim().split(" "); for(int index = 0;index < n; index++){ arr[index] = Integer.parseInt(elements[index]); } Solution obj = new Solution(); System.out.println(obj.countSubarrays(arr, n, l, r)); } } } // } Driver Code Ends //User function Template for Java class Solution{ static long countSubarrays(int a[], int n, int L, int R) { long pre = 0; long preLow = 0; long count = 0; for (int i = 0; i < n; i++) { if (a[i] < L) { count += pre; preLow++; } else if (a[i] > R) { pre = 0; preLow = 0; } else { count += (pre + preLow + 1); pre += preLow + 1; preLow = 0; } } return count; } }
mpsslalitha/GFG-Solutions
Medium/Number of subarrays with maximum values in given range/number-of-subarrays-with-maximum-values-in-given-range.java
568
package day2; import java.util.Scanner; public class day76 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Masukkan jumlah jam kerja: "); int jamKerja = sc.nextInt(); System.out.print("Masukkan tarif per jam: "); int tarifPerJam = sc.nextInt(); System.out.print("Apakah Anda mendapatkan bonus besar-besaran? (Y/T)"); String jawaban = sc.next(); int gaji = jamKerja * tarifPerJam; if (jawaban.equalsIgnoreCase("Y")) { gaji += 500000; } System.out.println("Gaji buruh tali adalah Rp" + gaji); } }
riofebrian839/100day_of_coding
Day_87
569
public class j3dm { public static void main(String[] args) { system.out.println("GitHub dame mi camiseta 3/5!"); } }
Tonsoe/JavaPracticeHacktoberfest
j3dm
570
import java.util.*; public class E { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int m = scanner.nextInt(); int k = scanner.nextInt(); Map<Integer, Set<Integer>> routes = new TreeMap<>(); for (int i = 0; i < m; i++) { int key = scanner.nextInt(); int value = scanner.nextInt(); if (!routes.containsKey(key)){ routes.put(key, new TreeSet<>()); } routes.get(key).add(value); if (!routes.containsKey(value)){ routes.put(value, new TreeSet<>()); } routes.get(value).add(key); } int[] distances = new int[n]; Arrays.fill(distances, Integer.MAX_VALUE); int[] exits = new int[k]; for (int i = 0; i<k;i++){ exits[i] = scanner.nextInt(); distances[exits[i]-1] = 0; } for (int exit : exits) { ArrayList<Integer> visited = new ArrayList<>(); dfs(routes, distances, exit, 0,visited); } System.out.println(max(distances)); } public static void dfs(Map<Integer,Set<Integer>> map, int[] distances, int start, int distance,ArrayList<Integer> visited){ for (int destination: map.get(start)){ if (distance + 1 < distances[destination - 1] && !visited.contains(destination)){ distances[destination-1] = distance + 1; ArrayList<Integer> newVisited = new ArrayList<>(visited); newVisited.add(destination); dfs(map,distances,destination,distance + 1,newVisited); } } } public static int max(int[] array){ int max = Integer.MIN_VALUE; for (int i = 0; i<array.length;i++){ if (array[i] > max){ max = array[i]; } } return max; } }
swiftyx/UW-ICPC-Qualifier-2019
E.java
571
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.Socket; import java.net.ServerSocket; import java.util.ArrayList; import java.io.PrintWriter; import java.util.StringTokenizer; import java.util.HashMap; class ServerThread extends Thread { Socket s; public static ArrayList ulist, ilist, plist; private static Object mutex; public static int connected = 0; public int delindx; public static HashMap<String, String> mails; public ServerThread(Socket s) { this.s = s; System.out.println("Accepted Connection"); } //prints the current file list for debug. public static void printUlist() { for(int i = 0; i < ulist.size(); i++) System.out.println("IP: "+ ilist.get(i)+ " Port: "+ plist.get(i) + " user: "+ ulist.get(i)); } public void run() { int incomingPort, passSignin = 0; String incomingIP; incomingPort = s.getPort(); incomingIP = s.getInetAddress().toString(); try { BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream())); PrintWriter pw = new PrintWriter(s.getOutputStream(), true); String un = ""; while (true) { String message = br.readLine(); // client abnormal termination. if(message == null) { System.out.println("Client terminates connection"); break; } // checking if signed up. if( passSignin == 0) { char[] tmp = message.toCharArray(); if( message.startsWith("Signin ")) { synchronized(mutex) { String toAddShared = message.substring(7); ulist.add(toAddShared); un = toAddShared; ilist.add(incomingIP); plist.add(incomingPort); connected += 1; String okrp = "Ok\n"; pw.println(okrp); pw.flush(); passSignin = 1; } } else if( message.startsWith("mail ") && message.length() > 5) { /// Reception on Server-to-Server. //// message from another server to forward an email to one of it's users. String toUser, fromUser, tt, plaintext; tt = message.substring(5); toUser = tt.split(" ")[0]; fromUser = tt.split("-")[1].split(" ")[0]; //mail user from-user text plaintext = tt.split("-")[1].substring(fromUser.length()+1); if(ulist.contains(toUser)) { pw.println("Ok"); pw.flush(); // do the appropriate handlings HashMap etc. if(mails.containsKey(toUser)) mails.put(toUser, mails.get(toUser) + fromUser + ":" + plaintext + " "); else mails.put(toUser, fromUser + ":" + plaintext); } else { System.out.println("Not having recipient as a client: "); continue; } } }else{ if( message.startsWith("mail ") ) { // to contact another email Server.(Server- to Server).Received from connected client. /// Send on Server-to-Server. String serport, serip, userto, plaintext; String tt; tt = message.substring(5); userto = tt.split("@")[0]; serip = tt.split("@")[1].split(":")[0]; serport = tt.split("@")[1].split(":")[1].split(" ")[0]; plaintext = tt.substring(userto.length() + serip.length() + serport.length() + 3); String cmdts = "mail " + userto+" from-" + un + " " + plaintext; Socket pps = new Socket(serip, Integer.parseInt(serport)); PrintWriter pwpp = new PrintWriter(pps.getOutputStream()); BufferedReader brpp = new BufferedReader(new InputStreamReader(pps.getInputStream())); pwpp.println(cmdts); pwpp.flush(); pw.println("ok"); pw.flush(); String respSS = brpp.readLine(); if(respSS.equals("Ok")) System.out.println("Mail Server transfer succeed."); try { pps.close(); } catch(IOException e) { System.out.println("Failed to close S-S socket"); } } else if( message.startsWith("Signout")) { synchronized(mutex) { //get index of the particular client to remove from all lists. for(int i = 0; i < connected; i++) if( (int) plist.get(i) == incomingPort) delindx = i; plist.remove(delindx); ilist.remove(delindx); ulist.remove(delindx); connected -= 1; } } else if( message.equals("mail") ) { // from client to read emails String mailreply; if( mails.containsKey(un) == false) mailreply = "no messages"; else mailreply = mails.get(un); pw.println(mailreply); pw.flush(); } } printUlist(); } } catch (IOException e) { e.printStackTrace(); } } public static void main(String args[]) { ulist = new ArrayList(); ilist = new ArrayList(); plist = new ArrayList(); mails = new HashMap<String, String>(); int serverport; serverport = Integer.parseInt(args[0]); ServerSocket serverSocket = null; mutex = new Object(); try { serverSocket = new ServerSocket(serverport); } catch (Exception ex) { ex.printStackTrace(); } while (true) { Socket clientSocket = null; try { //returns a new socket(client socket) and is passed to the thread as an argument.. clientSocket = serverSocket.accept(); new ServerThread(clientSocket).start(); } catch (IOException e) { e.printStackTrace(); } } } }
NikosMouzakitis/email_server_distributed_systems
s.java
572
import java.util.*; public class G { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); System.out.println(m(n)); } static Map<Integer, Integer> map = new HashMap<>(); static int m(int n) { // System.out.println(n); if (map.containsKey(n)) { return map.get(n); } if (n < 9) { return n * 2 -1; } int i = 2; int k = (int)Math.sqrt(n); int power = (int) Math.pow(k, i); int newPower = power; do { power = newPower; int step = m (n - power); int cur = m(k); int r = step + i * (cur + 3); if (!map.containsKey(n)) { map.put(n, r); } else if (map.get(n) > r) { map.put(n, r); } i++; k = (int) (Math.pow(n, 1. / i) + 1e-10); newPower = (int) Math.pow(k, i); } while (newPower > power); return map.get(n); // if (n < ) } }
swiftyx/UW-ICPC-Qualifier-2019
G.java
573
import java.util.Scanner; public class a { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a = sc.nextInt(); //145 int f = a; int p = 0; int fact = 1; int sum = 0; while (f!=0) { p = f%10; // 5 for (int j = 1 ; j<=p ; j++) // p = 2 { fact = fact * j; } sum = sum + fact; // sum = 1 f = f/10; fact = 1; } } }
TejuGabbu/Java-Basic-Programs
a.java
575
import java.util.Scanner; public class Salario { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); // Ingreso de datos por teclado System.out.print("Ingrese el valor de la hora: "); double valorHora = scanner.nextDouble(); System.out.print("Ingrese el número de horas trabajadas: "); int horasTrabajadas = scanner.nextInt(); // Cálculo del salario total double salarioTotal = valorHora * horasTrabajadas; // Cálculo de la retención en la fuente (5%) double retencionFuente = salarioTotal * 0.05; // Cálculo del salario neto double salarioNeto = salarioTotal - retencionFuente; // Impresión de resultados System.out.println("Salario total: $" + salarioTotal); System.out.println("Retención en la fuente: $" + retencionFuente); System.out.println("Salario neto: $" + salarioNeto); } }
Tupap1/Actalgoritmo
1.java
576
import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; public class B { public static void main(String[] args) { System.out.println("enter your name: "); Scanner sc = new Scanner(System.in); String str = sc.next(); String str1=str.toString(); int count = 0; Pattern p = Pattern.compile("[a-zA-Z^6-9]"); Matcher m = p.matcher(str1); while (m.find()) { count++; } if (count != 0 ) { System.out.println("Error input"); } else { System.out.println("Input accepted"); } } }
Shadow-Code-Fighter/practice_java_code
B.java
577
public class Hello { public static void main(String[] args) { // Prints "Hello, World" in the terminal window. System.out.println("Hello, World"); } }
gbogguru/API
Hello.java
578
public class Solution { public static void main(String[] args) { System.out.println("Hello, World."); System.out.println("Hello, Java."); } }
VChristinne/hackerrank
Java/Welcome to Java.java
580
//save as B.java import pack.simple; class B{ public static void main(String[] args) { simple A = new simple(); A.simple1(); } }
shabh2412/Algorithms
B.java
581
public class Docker { public static void main(String[] args) { Runtime runtime = Runtime.getRuntime(); int processors = runtime.availableProcessors(); long maxMemory = runtime.maxMemory(); double mb = Math.pow(2, 20); double gb = Math.pow(2, 30); System.out.println("cpu: " + processors); System.out.println("mem: " + (maxMemory / gb)); } }
ahoward/tf-jvm-docker-mem
a.java
582
class Solution { public boolean PredictTheWinner(int[] nums) { final int n = nums.length; // dp[i][j] := max number you can get more than your opponent in nums[i..j] int[][] dp = new int[n][n]; for (int i = 0; i < n; ++i) dp[i][i] = nums[i]; for (int d = 1; d < n; ++d) for (int i = 0; i + d < n; ++i) { final int j = i + d; dp[i][j] = Math.max(nums[i] - dp[i + 1][j], nums[j] - dp[i][j - 1]); } return dp[0][n - 1] >= 0; } }
MonitSharma/LeetCode-Solutions
486-Predict the Winner/solution.java
583
import java.util.*; public class test { public static void main(String[] args) { Scanner in = new Scanner(System.in); Deque<Integer> deque = new ArrayDeque<>(); HashSet<Integer> set = new HashSet<>(); int n = in.nextInt(); int m = in.nextInt(); int maxUnique = 0; for (int i = 0; i < n; i++) { int num = in.nextInt(); deque.addLast(num); set.add(num); // If the size of the deque exceeds M, remove elements from the front // and also remove them from the set if they're not repeated in the deque if (deque.size() > m) { int removed = deque.removeFirst(); if (!deque.contains(removed)) { set.remove(removed); } } // Update maxUnique if necessary if (deque.size() == m) { maxUnique = Math.max(maxUnique, set.size()); } } System.out.println(maxUnique); } }
Titlinath/java
d.java
584
import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static void main(String[] args) { System.out.println("Hello"); } }
guezandy/algorithmChallenges
1.java
585
public class f { public static void main(String[] args) { int x = Integer.valueOf(args[0]); int y = Integer.valueOf(args[1]); System.out.println("f("+args[0]+","+args[1]+")="+f(x,y)); } public static int f(int x, int y){ int a = x+1; if (x == 0) return g(y,x,y); else return a+g(f(x-1,y),x,y); } public static int g(int n, int x, int y){ int a = x+y; if (n == 0) return 0; else return h(n-1, a,x,y); } public static int h(int k, int a, int x, int y){ if (k == 0) return 0; else return a+(k+1)+g(k,x,y); } }
Frichetten/Programming-Language-Theory
f.java
586
/** * arr */ import java.util.*; class a{ public static void main(String[] args) { int a[]=new int[5] ; Scanner sc=new Scanner(System.in); for(int i=0;i<a.length;i++) { a[i]=sc.nextInt(); } for(int i=0;i<a.length;i++) { System.out.println(a[i]); } } }
ganesh-b45/JavaProgramming
s.java
587
import java.util.*; public class T { public static void main(String[] args){ /*Scanner sc=new Scanner(System.in); System.out.println("Enter the value ="); int a = sc.nextInt(); System.out.println("the value of a is =" + a);*/ //int a =1,b=2,c; //-----addition-------- /*c=a+b; System.out.println(c);*/ //-----Subtraction----- /*c=a-b; System.out.println(c);*/ //-----multiplication--- /*c=a*b; System.out.println(c);*/ //-----division------- /*c=a/b; System.out.println(c);*/ //-----modulus-------- /*c=a%b; System.out.println(c);*/ //-----Area of cicle-------- /*int radius=5; float result; result=3.14f*radius*radius; System.out.println(result);*/ //-----Area of square------- /*int area=a*a; System.out.println("the area of square =" + area);*/ //-----Area of rectangle---- /*int area=a*b; System.out.println("the area of rectangle =" + area);*/ //-----Area of cylinder----- /*float area; int l=5; int radius = 2; area=2*3.14f*radius*l+2*3.14f*radius*radius; System.out.println("the area of cylinder =" + area);*/ //-----Area of sphere------- /*float area; int radius = 2; area= 4*3.14f*radius*radius; System.out.println("the area of sphere =" + area);*/ //-----Area of cicle input given by user--------- /*Scanner sc=new Scanner(System.in); System.out.print("Enter the radius ="); int radius=sc.nextInt(); float area=3.14f*radius*radius; System.out.println("Area of circle =" + area);*/ //-----Area of square input given by user--------- /*Scanner sc=new Scanner(System.in); System.out.print("Enter the side ="); int radius=sc.nextInt(); int area=radius*radius; System.out.println("Area of area =" + area);*/ //-----Area of rectangle input given by user------ /*Scanner sc=new Scanner(System.in); System.out.print("Enter the sides ="); int radius1=sc.nextInt(); int radius2=sc.nextInt(); int area=radius1*radius2; System.out.println("Area of rectangle =" + area);*/ //------Area of cylinder input given by user------- /*Scanner sc=new Scanner(System.in); System.out.print("Enter the radius ="); int radius=sc.nextInt(); System.out.print("Enter the height ="); int l=sc.nextInt(); float area=2*3.14f*radius*l+2*3.14f*radius*radius; System.out.println("Area of cylinder =" + area);*/ //------Area of sphere input given by user--------- /*Scanner sc=new Scanner(System.in); System.out.print("Enter the radius ="); int radius=sc.nextInt(); float area=4*3.14f*radius*radius; System.out.println("Area of sphere =" + area);*/ //------volume of cylinder------- /*float area; int l=5; int radius = 2; area=3.14f*radius*radius*l; System.out.println("the volume of cylinder =" + area);*/ //------Volume of cylinder input given by user--------- /*Scanner sc=new Scanner(System.in); System.out.print("Enter the radius ="); int radius=sc.nextInt(); System.out.print("Enter the height ="); int l=sc.nextInt(); float area=3.14f*radius*radius*l; System.out.println("volume of cylinder =" + area);*/ //------volume of sphere--------- /*float area; int radius = 2; area= 4/3*3.14f*radius*radius*radius; System.out.println("the volume of sphere =" + area);*/ //------Volume of sphere input given by user-------- /*Scanner sc=new Scanner(System.in); System.out.print("Enter the radius ="); int radius=sc.nextInt(); float area=4/3*3.14f*radius*radius*radius; System.out.println("Volume of sphere =" + area);*/ //------Celsius to fahrebheit-------- /*Scanner sc=new Scanner(System.in); System.out.print("Enter the temperature in celsius ="); float celsius=sc.nextFloat(); float fahrebheit=(celsius*9/5)+32; System.out.println("fahrebheit =" + fahrebheit);*/ //------Kelvin to Celsius---------- /*Scanner sc=new Scanner(System.in); System.out.print("Enter the temperature in kelvin ="); float kelvin=sc.nextFloat(); float celsius=kelvin-273.15f; System.out.println("celsius =" + celsius);*/ //------Print strings--------- /*String d="hello"; System.out.println(d + " world");*/ /*String d="Amit"; System.out.println(d + " is a developer");*/ /*String d="mango"; System.out.println(d + " is a king");*/ /*String d="You"; System.out.println(d + " are the best person");*/ /*String d="Earth"; System.out.println("This is a " + d);*/ /*String d="hello"; System.out.println("hii " + d + " how are you");*/ //------Arithmetical operator question--------- /*int e=23+78*34; System.out.println(e);*/ /*float e=23+67-(3.4f-7); System.out.println(e);*/ /*float e=1.2f+4.5f*1.2f-(2.3f*45); System.out.println(e);*/ /*int e=23*23+67-(23*2)/2; System.out.println(e);*/ /*int e=34+56-23*(12%23); System.out.println(e);*/ /*float e=(5.6f*2-5)-7%23; System.out.println(e);*/ /*int e=1+34/78; System.out.println(e);*/ /*int e=32/2; System.out.println(e);*/ /*int e=24%2; System.out.println(e);*/ /*float e=34+2.3f*(12-98*3.4f)-9.2f+34; System.out.println(e);*/ } }
Lkgupta9723/july28
T.java
588
public class Hello { public static void main(String[] args) { System.out.println("Hello, world from GIT!"); } }
kjvv077/hw-git
mine.java
589
class Main { public static void main(String[] args) { // create an array int[] age = {12, 4, 5, 2, 5}; // access each array elements System.out.println("Accessing Elements of Array:"); System.out.println("First Element: " + age[0]); System.out.println("Second Element: " + age[1]); System.out.println("Third Element: " + age[2]); System.out.println("Fourth Element: " + age[3]); System.out.println("Fifth Element: " + age[4]); } }
chetanbhasney02/Java-Codes
arrayelement.java
590
public class B { public static void main() { System.out.println("Hello B"); } }
comius/bazel-multirelease-transitions
B.java
592
import java.util.*; class largestelementmatrix { public static void main(String args[]) { int a[][]=new int[30][30]; int r,c,i,j,large; Scanner input=new Scanner(System.in); System.out.println("Enter the number of rows and columns"); r=input.nextInt(); c=input.nextInt(); System.out.println("enter the elements"); for(i=0;i<r;i++) for(j=0;j<c;j++) a[i][j]=input.nextInt(); large=a[0][0]; for(i=0;i<r;i++) { for(j=0;j<c;j++) { if(large<a[i][j]) large=a[i][j]; } } System.out.println("The largest element is"+" "+large); } }
miraz00/exp2
5.java
594
import javax.swing.*; import java.awt.event.*; class Calc implements ActionListener { JFrame f; JTextField t; JButton b1,b2,b3,b4,b5,b6,b7,b8,b9,b0,bdiv,bmul,bsub,badd,bdec,beq,bdel,bclr; static double a=0,b=0,result=0; static int operator=0; Calc() { f=new JFrame("Calculator"); t=new JTextField(); b1=new JButton("1"); b2=new JButton("2"); b3=new JButton("3"); b4=new JButton("4"); b5=new JButton("5"); b6=new JButton("6"); b7=new JButton("7"); b8=new JButton("8"); b9=new JButton("9"); b0=new JButton("0"); bdiv=new JButton("/"); bmul=new JButton("*"); bsub=new JButton("-"); badd=new JButton("+"); bdec=new JButton("."); beq=new JButton("="); bdel=new JButton("Delete"); bclr=new JButton("Clear"); t.setBounds(30,40,280,30); b7.setBounds(40,100,50,40); b8.setBounds(110,100,50,40); b9.setBounds(180,100,50,40); bdiv.setBounds(250,100,50,40); b4.setBounds(40,170,50,40); b5.setBounds(110,170,50,40); b6.setBounds(180,170,50,40); bmul.setBounds(250,170,50,40); b1.setBounds(40,240,50,40); b2.setBounds(110,240,50,40); b3.setBounds(180,240,50,40); bsub.setBounds(250,240,50,40); bdec.setBounds(40,310,50,40); b0.setBounds(110,310,50,40); beq.setBounds(180,310,50,40); badd.setBounds(250,310,50,40); bdel.setBounds(60,380,100,40); bclr.setBounds(180,380,100,40); f.add(t); f.add(b7); f.add(b8); f.add(b9); f.add(bdiv); f.add(b4); f.add(b5); f.add(b6); f.add(bmul); f.add(b1); f.add(b2); f.add(b3); f.add(bsub); f.add(bdec); f.add(b0); f.add(beq); f.add(badd); f.add(bdel); f.add(bclr); f.setLayout(null); f.setVisible(true); f.setSize(350,500); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setResizable(false); b1.addActionListener(this); b2.addActionListener(this); b3.addActionListener(this); b4.addActionListener(this); b5.addActionListener(this); b6.addActionListener(this); b7.addActionListener(this); b8.addActionListener(this); b9.addActionListener(this); b0.addActionListener(this); badd.addActionListener(this); bdiv.addActionListener(this); bmul.addActionListener(this); bsub.addActionListener(this); bdec.addActionListener(this); beq.addActionListener(this); bdel.addActionListener(this); bclr.addActionListener(this); } public void actionPerformed(ActionEvent e) { if(e.getSource()==b1) t.setText(t.getText().concat("1")); if(e.getSource()==b2) t.setText(t.getText().concat("2")); if(e.getSource()==b3) t.setText(t.getText().concat("3")); if(e.getSource()==b4) t.setText(t.getText().concat("4")); if(e.getSource()==b5) t.setText(t.getText().concat("5")); if(e.getSource()==b6) t.setText(t.getText().concat("6")); if(e.getSource()==b7) t.setText(t.getText().concat("7")); if(e.getSource()==b8) t.setText(t.getText().concat("8")); if(e.getSource()==b9) t.setText(t.getText().concat("9")); if(e.getSource()==b0) t.setText(t.getText().concat("0")); if(e.getSource()==bdec) t.setText(t.getText().concat(".")); if(e.getSource()==badd) { a=Double.parseDouble(t.getText()); operator=1; t.setText(""); } if(e.getSource()==bsub) { a=Double.parseDouble(t.getText()); operator=2; t.setText(""); } if(e.getSource()==bmul) { a=Double.parseDouble(t.getText()); operator=3; t.setText(""); } if(e.getSource()==bdiv) { a=Double.parseDouble(t.getText()); operator=4; t.setText(""); } if(e.getSource()==beq) { b=Double.parseDouble(t.getText()); switch(operator) { case 1: result=a+b; break; case 2: result=a-b; break; case 3: result=a*b; break; case 4: result=a/b; break; default: result=0; } t.setText(""+result); } if(e.getSource()==bclr) t.setText(""); if(e.getSource()==bdel) { String s=t.getText(); t.setText(""); for(int i=0;i<s.length()-1;i++) t.setText(t.getText()+s.charAt(i)); } } public static void main(String...s) { new Calc(); } }
PaulThomas20002/S3-OBJECT-ORIENTED-PROGRAMMING-LAB-IN-JAVA
Cycle-5/Calc.java
595
// package JAVA; class p { public static void main(String[] args) { System.out.println("HELLO WORLD"); } }
PIYUSH-NAYAK/JAVA
p.java
597
import java.util.Arrays; import java.util.Scanner; public class B { public static void maxMini(int [] arr){ //Using Sorting Arrays.sort(arr); int min = arr[0]; int max = arr[arr.length-1]; System.out.println("Min: "+min+" Max: "+max); } public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter the size of the array: "); int n = sc.nextInt(); int originalArr[] = new int[n]; System.out.print("Enter the elements in to the array: "); for (int i = 0; i < n; i++) { originalArr[i]=sc.nextInt(); } maxMini(originalArr); } } /* * Given an array of size N. The task is to find the maximum and the minimum element of the array using the minimum number of comparisons. Examples: Input: arr[] = {3, 5, 4, 1, 9} Output: Minimum element is: 1 Maximum element is: 9 Input: arr[] = {22, 14, 8, 17, 35, 3} Output: Minimum element is: 3 Maximum element is: 35 */
arsh0007/DSACheatSheet450
B.java
598
import java.io.*; import java.util.*; public class b { public class Tree { int supervisor; Tree left, right; public Tree(int S, Tree L, Tree R) { supervisor = S; left = L; right = R; } } public static void main(String [] args) throws IOException { Scanner in = new Scanner(System.in); int numCases = in.nextInt(); for(int i = 0; i < numCases; i++) { int numEmp = in.nextInt(); int [] emp = new int[numEmp-1]; emp[0] = -1; for(int j = 1; j < numEmp; j++) { emp[j] = in.nextInt(); } for(int j = 1; j < numEmp; j++) { } } } }
isabelacmor/programmingteam
b.java
600
/* The design principle used in the provided code is the Dependency Inversion Principle (DIP). The Dependency Inversion Principle (DIP) states that high-level modules should not depend on low-level modules. Both should depend on abstractions, and abstractions should not depend on details. In simpler terms, it suggests that classes should depend on abstractions (interfaces or abstract classes) rather than concrete implementations. */ interface NotificationSender { void sendNotification (String message); } class EmailSender implements NotificationSender { @Override public void sendNotification(String message) { // Code to send an email System.out.println("Sending email: "+message); } } class User { private NotificationSender notificationSender; public User (NotificationSender notificationSender){ this.notificationSender = notificationSender; //Dependency on NotificationSender } public void notifyUser(String message){ notificationSender.sendNotification(message); } } public class D { public static void main(String args[]){ NotificationSender emailSender = new EmailSender(); // Dependency Injection User user = new User (emailSender); user.notifyUser("Hello, this is an email notification!"); } }
Lakhan-Gurjar/SOLID-Design-Principles
D.java
601
import io.netty.util.ResourceLeakDetector; import io.netty.util.ResourceLeakDetector.Level; public class f { public static final ResourceLeakDetector.Level a = ResourceLeakDetector.Level.DISABLED; public static boolean a(char ☃) { return (☃ != '§') && (☃ >= ' ') && (☃ != ''); } public static final char[] b = { '/', '\n', '\r', '\t', '\000', '\f', '`', '?', '*', '\\', '<', '>', '|', '"', ':' }; public static String a(String ☃) { StringBuilder ☃ = new StringBuilder(); for (char ☃ : ☃.toCharArray()) { if (a(☃)) { ☃.append(☃); } } return ☃.toString(); } static { ResourceLeakDetector.setLevel(a); } }
MCLabyMod/LabyMod-1.9
f.java
608
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode() {} * TreeNode(int val) { this.val = val; } * TreeNode(int val, TreeNode left, TreeNode right) { * this.val = val; * this.left = left; * this.right = right; * } * } */ class Solution { public int amountOfTime(TreeNode root, int start) { Map<Integer, Set<Integer>> map = new HashMap<>(); convert(root, 0, map); Queue<Integer> queue = new LinkedList<>(); queue.add(start); int minute = 0; Set<Integer> visited = new HashSet<>(); visited.add(start); while (!queue.isEmpty()) { int levelSize = queue.size(); while (levelSize > 0) { int current = queue.poll(); for (int num : map.get(current)) { if (!visited.contains(num)) { visited.add(num); queue.add(num); } } levelSize--; } minute++; } return minute - 1; } public void convert(TreeNode current, int parent, Map<Integer, Set<Integer>> map){ if (current == null) { return; } if (!map.containsKey(current.val)) { map.put(current.val, new HashSet<>()); } Set<Integer> adjacentList = map.get(current.val); if (parent != 0) { adjacentList.add(parent); } if (current.left != null) { adjacentList.add(current.left.val); } if (current.right != null) { adjacentList.add(current.right.val); } convert(current.left, current.val, map); convert(current.right, current.val, map); } }
akshaykumar7591/Leetcode_Daily_Challenges_Solution
LeetCode_Daily_Question_Solution/2385. Amount of Time for Binary Tree to Be Infected
609
//package com.company; // Always comment out package when submitting. import java.io.*; import java.util.*; public class Main { public static class Task { long[][] lengthCoef; long[][] latsum; public void solveForLength(int l) { int coefs = l / 2; long large = 1; long small = 1; for (int i = 0; i < l - 1; i++) { large *= 10; } lengthCoef[l] = new long[coefs]; for (int i = 0; i < coefs; i++) { lengthCoef[l][i] = large - small; large /= 10; small *= 10; } latsum[l] = new long[coefs]; if (coefs - 1>=0) latsum[l][coefs - 1] = lengthCoef[l][coefs - 1]; for (int i = coefs - 2; i >= 0; i--) { latsum[l][i] = latsum[l][i + 1] + lengthCoef[l][i]; } // System.err.println(Arrays.toString(lengthCoef[l])); } public long dfs(long[] cfs, long[] lat, int i, long remain) { // [-9, 9] if (i == cfs.length ) { return remain == 0 ? 1 : 0; } if (lat[i] * 9 + remain < 0) return 0; if (lat[i] * -9 + remain > 0) return 0; int cnt = 0; for (int j = -9; j < 10; j++) { int times = j < 0 ? j + 10: -j + 10; if (i == 0) times--; cnt += times * dfs(cfs, lat,i + 1, remain + (long) j * cfs[i]); } return cnt; } public void solve(Scanner sc, PrintWriter pw) throws IOException { int sz = 19; lengthCoef = new long[sz][]; latsum = new long[sz][]; for (int i = 1; i < sz; i++) { solveForLength(i); } int D = sc.nextInt(); if (D % 9 != 0){ pw.println(0); return; } int cnt = 0; for (int i = 1; i < sz; i++) { long t = dfs(lengthCoef[i], latsum[i], 0, D); if (i % 2 == 1) t *= i == 1 ? 9 : 10; cnt += t; } pw.println(cnt); } } // template, actual code is in class Task. static long TIME_START, TIME_END; public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); // Scanner sc = new Scanner(new FileInputStream("Test.in")); PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out)); // PrintWriter pw = new PrintWriter(new FileOutputStream("Test.out")); Runtime runtime = Runtime.getRuntime(); long usedMemoryBefore = runtime.totalMemory() - runtime.freeMemory(); TIME_START = System.currentTimeMillis(); Task t = new Task(); t.solve(sc, pw); TIME_END = System.currentTimeMillis(); long usedMemoryAfter = runtime.totalMemory() - runtime.freeMemory(); pw.close(); // System.err.println("Memory increased: " + (usedMemoryAfter - usedMemoryBefore) / 1000000); // System.err.println("Time used: " + (TIME_END - TIME_START) + "."); } // Faster IO with BufferedReader wrapped with Scanner static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(FileReader s) throws FileNotFoundException { br = new BufferedReader(s); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public boolean ready() throws IOException { return br.ready(); } } }
Intelligent-CAT-Lab/CodeMind
dataset/CodeNet/CodeNet-Java/p03704_s154597034/Main.java
611
/** * 2022 AP Computer Science Exam - Free Response Questions (FRQ) * Problems definition: https://apcentral.collegeboard.org/pdf/ap22-frq-computer-science-a.pdf * Solutions for question 2. */ public class Textbook extends Book { private int edition; public Textbook(String bookTitle, double bookPrice, int bookEdition) { super(bookTitle, bookPrice); edition = bookEdition; } public int getEdition() { return edition; } public String getBookInfo() { return super.getBookInfo() + "-" + edition; } public boolean canSubstituteFor(Textbook t) { return getTitle().equals(t.getTitle()) && getEdition() >= t.getEdition(); } }
superpenguin612/ap-csa-frq-2022
2.java
613
import java.math.BigInteger; import java.util.HashSet; import java.util.Scanner; import java.util.Set; public class LatticePaths { // http://www.robertdickau.com/lattices.html public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int tests = Integer.parseInt(scanner.nextLine()); for (int i = 0; i < tests; i++) { String[] numbers = scanner.nextLine().split("\\s+"); int n = Integer.parseInt(numbers[0]); int m = Integer.parseInt(numbers[1]); Set<Integer> nFactorialMembers = new HashSet<>(); for (int j = 1; j <= n; j++) { nFactorialMembers.add(j); } Set<Integer> mFactorialMembers = new HashSet<>(); for (int j = 1; j <= m; j++) { mFactorialMembers.add(j); } Set<Integer> mnFactorialMembers = new HashSet<>(); for (int j = 1; j <= m + n; j++) { mnFactorialMembers.add(j); } // (m+n) chose m === (m+n)!/m!n! // divided n! mnFactorialMembers.removeAll(nFactorialMembers); BigInteger result = BigInteger.ONE; for (Integer k : mnFactorialMembers) { result = result.multiply(new BigInteger(k.toString())); } for (Integer k : mFactorialMembers) { result = result.divide(new BigInteger(k.toString())); } System.out.println(result.mod(new BigInteger("1000000007"))); } scanner.close(); } }
PaulNoth/hackerrank
contest/project_euler+/015_lattice_paths/LatticePaths.java
614
//Write a program to find the shortest path between vertices using bellman-ford algorithm. import java.util.Scanner; public class BellmanFord { int d[],noofvertices; public BellmanFord(int noofvertices) { this.noofvertices = noofvertices; d = new int[noofvertices + 1]; } public static void main(String[] args) { int noofvertices,source; Scanner s = new Scanner(System.in); System.out.println("Enter the number of vertices:"); noofvertices = s.nextInt(); int a[][] = new int[noofvertices + 1][noofvertices + 1]; System.out.println("Enter the adjacency matrix:"); for(int sn = 1; sn <= noofvertices; sn++) { for(int dn = 1; dn <= noofvertices; dn++) { a[sn][dn] = s.nextInt(); if(sn == dn) { a[sn][dn] = 0; continue; } if(a[sn][dn] == 0) a[sn][dn] = 999; } } System.out.println("Enter src vertex:"); source = s.nextInt(); BellmanFord b = new BellmanFord(noofvertices); b.bellmanFordeval(source,a); } private void bellmanFordeval(int source, int[][] a) { for(int node = 1; node <= noofvertices; node++) d[node] = 999; d[source] = 0; for(int node = 1; node <= noofvertices-1; node++) for(int sn=1; sn <= noofvertices; sn++) for(int dn = 1;dn <= noofvertices; dn++) if(a[sn][dn] != 999) if(d[dn] > d[sn]+a[sn][dn]) d[dn] = d[sn]+a[sn][dn]; for(int sn = 1; sn <= noofvertices; sn++) for(int dn = 1; dn <= noofvertices; dn++) if(d[dn] > d[sn]+a[sn][dn]) System.out.println("-ve cycle"); for(int vertex = 1; vertex <= noofvertices; vertex++) System.out.println( source+" to "+ vertex +" is "+ d[vertex] ); } }
shreyashbandekar/JSS-CN.lab
3.java
616
//imports import QuizApplication.DatabaseConnection; import java.sql.*; import java.awt.event.ActionEvent; import java.text.SimpleDateFormat; import java.util.Date; import javax.swing.JOptionPane; import javax.swing.JRadioButton; import javax.swing.Timer; public class C extends javax.swing.JFrame { private String questionid = "1"; private String answer; private int min = 0; private int sec = 0; private int marks = 0; private Timer time; /*default constructor*/ public C() { initComponents(); initQuiz(); } public C(String CMSID){ initComponents(); jLabel17.setText(CMSID); initQuiz(); } private void initQuiz() { setLocationRelativeTo(this); setDate(); setupTimer(); loadQuestion(); displayStudentInfo(); } private void setDate() { SimpleDateFormat dFormat = new SimpleDateFormat("dd-MM-yyyy"); Date date = new Date(); jLabel4.setText(dFormat.format(date)); } // Method to set up the timer private void setupTimer() { time = new Timer(1000, (ActionEvent e) -> { jLabel6.setText(String.format("%02d", sec)); jLabel5.setText(String.format("%02d", min)); if (sec == 60) { sec = 0; min++; if (min == 5) { time.stop(); answerCheck(); submit(); } } sec++; }); time.start(); } // Method to display student information private void displayStudentInfo() { try { Connection con = DatabaseConnection.getCon(); Statement st = con.createStatement(); ResultSet rs = st.executeQuery("select * from student where CMSID= '" + jLabel17 + "'"); if (rs.next()) { jLabel11.setText(rs.getString(2)); } } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } } public void answerCheck() { String studentAnswer = ""; if (jRadioButton1.isSelected()) { studentAnswer = jRadioButton1.getText(); } else if (jRadioButton2.isSelected()) { studentAnswer = jRadioButton2.getText(); } else if (jRadioButton3.isSelected()) { studentAnswer = jRadioButton3.getText(); } else if (jRadioButton4.isSelected()) { studentAnswer = jRadioButton4.getText(); } else { // No option selected JOptionPane.showMessageDialog(null, "Please select an option before proceeding."); return; // Exit the method to prevent proceeding to the next question } if (studentAnswer.equals(answer)) { marks++; jLabel15.setText(String.valueOf(marks)); } // Increment question number int question_id1 = Integer.parseInt(questionid); question_id1++; questionid = String.valueOf(question_id1); // Clear radio buttons cppbutton.clearSelection(); jLabel13.setText(questionid); // Check if it's the last question if (questionid.equals("11")) { jButton1.setVisible(false); submit(); } else { loadQuestion(); } } // Method to submit the quiz results public void submit() { String CMSID = jLabel17.getText(); try { Connection con = DatabaseConnection.getCon(); Statement st = con.createStatement(); st.executeUpdate("update student set marks='" + marks + "'where CMSID ='" + CMSID + "'"); setVisible(false); String marks1 = Integer.toString(marks); new Submittedquiz(marks1).setVisible(true); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } } // Method to load the current question public void loadQuestion() { try { Connection con = DatabaseConnection.getCon(); Statement st = con.createStatement(); ResultSet rs1 = st.executeQuery("select * from cpp_quiz where question_id='" + questionid + "'"); if (rs1.next()) { jLabel13.setText(rs1.getString(1)); jLabel18.setText(rs1.getString(2)); jRadioButton1.setText(rs1.getString(3)); jRadioButton2.setText(rs1.getString(4)); jRadioButton3.setText(rs1.getString(5)); jRadioButton4.setText(rs1.getString(6)); answer = rs1.getString(7); } } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } } // Ensure only one radio button can be selected at a time. Clear other radio button selections private void clearOtherSelections(JRadioButton selectedButton) { if (selectedButton.isSelected()) { if (selectedButton != jRadioButton1) jRadioButton1.setSelected(false); if (selectedButton != jRadioButton2) jRadioButton2.setSelected(false); if (selectedButton != jRadioButton3) jRadioButton3.setSelected(false); if (selectedButton != jRadioButton4) jRadioButton4.setSelected(false); } } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { cppbutton = new javax.swing.ButtonGroup(); jPanel1 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); jLabel4 = new javax.swing.JLabel(); jLabel5 = new javax.swing.JLabel(); jLabel6 = new javax.swing.JLabel(); jLabel7 = new javax.swing.JLabel(); jLabel8 = new javax.swing.JLabel(); jLabel9 = new javax.swing.JLabel(); jPanel2 = new javax.swing.JPanel(); jLabel10 = new javax.swing.JLabel(); jLabel11 = new javax.swing.JLabel(); jLabel12 = new javax.swing.JLabel(); jLabel13 = new javax.swing.JLabel(); jLabel14 = new javax.swing.JLabel(); jLabel15 = new javax.swing.JLabel(); jLabel16 = new javax.swing.JLabel(); jLabel17 = new javax.swing.JLabel(); jLabel19 = new javax.swing.JLabel(); jLabel20 = new javax.swing.JLabel(); jLabel18 = new javax.swing.JLabel(); jRadioButton1 = new javax.swing.JRadioButton(); jRadioButton2 = new javax.swing.JRadioButton(); jRadioButton3 = new javax.swing.JRadioButton(); jRadioButton4 = new javax.swing.JRadioButton(); jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); jLabel22 = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout()); jPanel1.setBackground(new java.awt.Color(153, 153, 153)); jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout()); jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/index student.png"))); // NOI18N jPanel1.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(66, 29, 61, -1)); jLabel2.setFont(new java.awt.Font("Segoe UI Black", 0, 36)); // NOI18N jLabel2.setText("C++ Quiz"); jPanel1.add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(180, 40, -1, -1)); jLabel3.setFont(new java.awt.Font("Segoe UI Black", 0, 18)); // NOI18N jLabel3.setText("Total Time:"); jPanel1.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(740, 20, -1, -1)); jLabel4.setFont(new java.awt.Font("Segoe UI Black", 0, 18)); // NOI18N jLabel4.setText("jLabel4"); jPanel1.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(560, 60, -1, -1)); jLabel5.setFont(new java.awt.Font("Segoe UI", 1, 18)); // NOI18N jLabel5.setText("00"); jPanel1.add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(880, 60, -1, -1)); jLabel6.setFont(new java.awt.Font("Segoe UI Black", 0, 18)); // NOI18N jLabel6.setText("00"); jPanel1.add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(920, 60, -1, -1)); jLabel7.setFont(new java.awt.Font("Segoe UI Black", 0, 18)); // NOI18N jLabel7.setText("5 min"); jPanel1.add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(860, 20, -1, -1)); jLabel8.setFont(new java.awt.Font("Segoe UI Black", 0, 18)); // NOI18N jLabel8.setText("Time Taken:"); jPanel1.add(jLabel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(740, 60, -1, -1)); jLabel9.setFont(new java.awt.Font("Segoe UI Black", 0, 18)); // NOI18N jLabel9.setText("Date:"); jPanel1.add(jLabel9, new org.netbeans.lib.awtextra.AbsoluteConstraints(480, 60, -1, -1)); getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 1000, 120)); jPanel2.setBackground(new java.awt.Color(153, 153, 153)); jPanel2.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout()); jLabel10.setFont(new java.awt.Font("Segoe UI Black", 0, 18)); // NOI18N jLabel10.setText("Name:"); jPanel2.add(jLabel10, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 60, 60, -1)); jLabel11.setFont(new java.awt.Font("Segoe UI Black", 0, 18)); // NOI18N jLabel11.setText("jLabel11"); jPanel2.add(jLabel11, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 60, 80, -1)); jLabel12.setFont(new java.awt.Font("Segoe UI Black", 0, 18)); // NOI18N jLabel12.setText("Question no:"); jPanel2.add(jLabel12, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 90, 120, -1)); jLabel13.setFont(new java.awt.Font("Segoe UI Black", 0, 18)); // NOI18N jLabel13.setText("00"); jPanel2.add(jLabel13, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 90, 100, -1)); jLabel14.setFont(new java.awt.Font("Segoe UI Black", 0, 18)); // NOI18N jLabel14.setText("Marks:"); jPanel2.add(jLabel14, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 130, 100, -1)); jLabel15.setFont(new java.awt.Font("Segoe UI Black", 0, 18)); // NOI18N jLabel15.setText("00"); jPanel2.add(jLabel15, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 130, 100, -1)); jLabel16.setFont(new java.awt.Font("Segoe UI Black", 0, 18)); // NOI18N jLabel16.setText("CMS:"); jPanel2.add(jLabel16, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 170, 100, -1)); jLabel17.setFont(new java.awt.Font("Segoe UI Black", 0, 18)); // NOI18N jLabel17.setText("00"); jPanel2.add(jLabel17, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 170, 100, -1)); jLabel19.setFont(new java.awt.Font("Segoe UI Black", 0, 18)); // NOI18N jLabel19.setText("Total Questions:"); jPanel2.add(jLabel19, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 210, -1, -1)); jLabel20.setFont(new java.awt.Font("Segoe UI Black", 0, 18)); // NOI18N jLabel20.setText("10"); jPanel2.add(jLabel20, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 210, -1, -1)); getContentPane().add(jPanel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(750, 110, 250, 560)); jLabel18.setFont(new java.awt.Font("Segoe UI Black", 0, 18)); // NOI18N jLabel18.setText("Question"); getContentPane().add(jLabel18, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 150, 520, -1)); cppbutton.add(jRadioButton1); jRadioButton1.setFont(new java.awt.Font("Segoe UI Black", 0, 18)); // NOI18N jRadioButton1.setText("jRadioButton1"); jRadioButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jRadioButton1ActionPerformed(evt); } }); getContentPane().add(jRadioButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 210, 740, -1)); cppbutton.add(jRadioButton2); jRadioButton2.setFont(new java.awt.Font("Segoe UI Black", 0, 18)); // NOI18N jRadioButton2.setText("jRadioButton2"); jRadioButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jRadioButton2ActionPerformed(evt); } }); getContentPane().add(jRadioButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 260, 740, -1)); cppbutton.add(jRadioButton3); jRadioButton3.setFont(new java.awt.Font("Segoe UI Black", 0, 18)); // NOI18N jRadioButton3.setText("jRadioButton3"); jRadioButton3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jRadioButton3ActionPerformed(evt); } }); getContentPane().add(jRadioButton3, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 310, 750, -1)); cppbutton.add(jRadioButton4); jRadioButton4.setFont(new java.awt.Font("Segoe UI Black", 0, 18)); // NOI18N jRadioButton4.setText("jRadioButton4"); jRadioButton4.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jRadioButton4ActionPerformed(evt); } }); getContentPane().add(jRadioButton4, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 360, 740, -1)); jButton1.setBackground(javax.swing.UIManager.getDefaults().getColor("Actions.Blue")); jButton1.setFont(new java.awt.Font("Segoe UI Black", 0, 18)); // NOI18N jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Next.png"))); // NOI18N jButton1.setText("Next Question"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); getContentPane().add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 450, -1, -1)); jButton2.setBackground(javax.swing.UIManager.getDefaults().getColor("Actions.Blue")); jButton2.setFont(new java.awt.Font("Segoe UI Black", 0, 18)); // NOI18N jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/save.png"))); // NOI18N jButton2.setText("Submit Quiz"); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } }); getContentPane().add(jButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(450, 450, -1, -1)); jLabel22.setIcon(new javax.swing.ImageIcon(getClass().getResource("/quizback1.jpg"))); // NOI18N getContentPane().add(jLabel22, new org.netbeans.lib.awtextra.AbsoluteConstraints(-240, 80, -1, -1)); pack(); }// </editor-fold> private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: answerCheck(); } private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: int s = JOptionPane.showConfirmDialog(null, "Do you want to submit", "Select", JOptionPane.YES_NO_OPTION); if (s == 0) { answerCheck(); submit(); } } private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: clearOtherSelections(jRadioButton1); } private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: clearOtherSelections(jRadioButton2); } private void jRadioButton3ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: clearOtherSelections(jRadioButton3); } private void jRadioButton4ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: clearOtherSelections(jRadioButton4); } /** * @param args the command line arguments */ public static void main(String args[]) { /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(C.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(C.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(C.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(C.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new C().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.ButtonGroup cppbutton; private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel10; private javax.swing.JLabel jLabel11; private javax.swing.JLabel jLabel12; private javax.swing.JLabel jLabel13; private javax.swing.JLabel jLabel14; private javax.swing.JLabel jLabel15; private javax.swing.JLabel jLabel16; private javax.swing.JLabel jLabel17; private javax.swing.JLabel jLabel18; private javax.swing.JLabel jLabel19; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel20; private javax.swing.JLabel jLabel22; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel6; private javax.swing.JLabel jLabel7; private javax.swing.JLabel jLabel8; private javax.swing.JLabel jLabel9; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; private javax.swing.JRadioButton jRadioButton1; private javax.swing.JRadioButton jRadioButton2; private javax.swing.JRadioButton jRadioButton3; private javax.swing.JRadioButton jRadioButton4; // End of variables declaration }
fizza49/Quiz-Application-OOP-Project
C.java
617
class Solution { public int numTrees(int n) { return numTrees(1, n); } private int numTrees(int start, int end) { if (start >= end) { return 1; } int countUnique = 0; for (int i = start; i <= end; i++) { // take i as root countUnique += numTrees(start, i - 1) * numTrees(i + 1, end); } return countUnique; } }
luckykumardev/leetcode-solution
.java
618
class F { final static String SPACES = " "; public static String format(String s, int len){ int slen = len-s.length(); if(slen > SPACES.length()) slen = SPACES.length(); if(slen > 0) return SPACES.substring(0,slen)+s; else return s; } public static String format(Object x, int len){ return format(String.valueOf(x), len); } public static String format(long x, int len){ return format(String.valueOf(x), len); } public static String format(double x, int len){ return format(String.valueOf(x), len); } public static String format(char x, int len){ return format(String.valueOf(x), len); } }
DanAndreasson/distance-vector-routing
F.java
619
import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.awt.event.ActionListener; class CreateLoginForm extends JFrame implements ActionListener { //initialize button, panel, label, and text field JButton b1; JPanel newPanel; JLabel userLabel, passLabel; final JTextField textField1, textField2; //calling constructor CreateLoginForm() { //create label for username userLabel = new JLabel(); userLabel.setText("Username"); //set label value for textField1 //create text field to get username from the user textField1 = new JTextField(15); //set length of the text //create label for password passLabel = new JLabel(); passLabel.setText("Password"); //set label value for textField2 //create text field to get password from the user textField2 = new JPasswordField(15); //set length for the password //create submit button b1 = new JButton("SUBMIT"); //set label to button //create panel to put form elements newPanel = new JPanel(new GridLayout(3, 1)); newPanel.add(userLabel); //set username label to panel newPanel.add(textField1); //set text field to panel newPanel.add(passLabel); //set password label to panel newPanel.add(textField2); //set text field to panel newPanel.add(b1); //set button to panel //set border to panel add(newPanel, BorderLayout.CENTER); //perform action on button click b1.addActionListener(this); //add action listener to button setTitle("LOGIN FORM"); //set title to the login form } //define abstract method actionPerformed() which will be called on button click public void actionPerformed(ActionEvent ae) //pass action listener as a parameter { String userValue = textField1.getText(); //get user entered username from the textField1 String passValue = textField2.getText(); //get user entered pasword from the textField2 //check whether the credentials are authentic or not if (userValue.equals("[email protected]") && passValue.equals("test")) { //if authentic, navigate user to a new page //create instance of the NewPage CreateLoginForm page = new CreateLoginForm(); //make page visible to the user page.setVisible(true); //create a welcome label and set it to the new page JLabel wel_label = new JLabel("Welcome: "+userValue); page.getContentPane().add(wel_label); } else{ //show error message System.out.println("Please enter valid username and password"); } } } //create the main class class loginpage { //main() method start public static void main(String arg[]) { try { //create instance of the CreateLoginForm CreateLoginForm form = new CreateLoginForm(); form.setSize(300,100); //set size of the frame form.setVisible(true); //make form visible to the user } catch(Exception e) { //handle exception JOptionPane.showMessageDialog(null, e.getMessage()); } } }
Sshiril/Javafiles
loginform.java
620
package cnLAB; import java.util.Scanner; public class BellmanFord { private int D[]; private int num_ver; public static final int MAX_VALUE = 999; public BellmanFord(int num_ver) { this.num_ver = num_ver; D = new int[num_ver + 1]; } public void BellmanFordEvaluation(int source, int A[][]) { for (int node = 1; node <= num_ver; node++) { D[node] = MAX_VALUE; } D[source] = 0; for (int node = 1; node <= num_ver - 1; node++) { for (int sn = 1; sn <= num_ver; sn++) { for (int dn = 1; dn <= num_ver; dn++) { if (A[sn][dn] != MAX_VALUE) { if (D[dn] > D[sn] + A[sn][dn]) D[dn] = D[sn] + A[sn][dn]; } } } } for (int sn = 1; sn <= num_ver; sn++) { for (int dn = 1; dn <= num_ver; dn++) { if (A[sn][dn] != MAX_VALUE) { if (D[dn] > D[sn] + A[sn][dn]) System.out.println("The Graph contains negative egde cycle"); } } } for (int vertex = 1; vertex <= num_ver; vertex++) { System.out.println("distance of source " + source + " to " + vertex + " is " + D[vertex]); } } public static void main(String[] args) { int num_ver = 0; int source; Scanner scanner = new Scanner(System.in); System.out.println("Enter the number of vertices"); num_ver = scanner.nextInt(); int A[][] = new int[num_ver + 1][num_ver + 1]; System.out.println("Enter the adjacency matrix"); for (int sn = 1; sn <= num_ver; sn++) { for (int dn = 1; dn <= num_ver; dn++) { A[sn][dn] = scanner.nextInt(); if (sn == dn) { A[sn][dn] = 0; continue; } if (A[sn][dn] == 0) { A[sn][dn] = MAX_VALUE; } } } System.out.println("Enter the source vertex"); source = scanner.nextInt(); BellmanFord b = new BellmanFord(num_ver); b.BellmanFordEvaluation(source, A); scanner.close(); } }
prashanth-106/CN
5.java
622
/* ***** * * ***** * * ***** */ class B{ public static void main(String[] args){ int i,j; for(i=1;i<=5;i++) { for(j=1;j<=5;j++) { if(i==1 ||i==5||j==1||j==5||i==(5/2+1)){ System.out.print("*"); } else System.out.print(" "); } System.out.println(); } } }
Yaduttam95/Java
B.java
623
/* * * * ***** * * * * */ class A{ public static void main(String args[]){ int i,j,k; for(i=1;i<=5;i++){ for(k=1;k<=5-i;k++){ System.out.print(" "); } for(j=1;j<=2*i-1;j++){ if(j==1||j==2*i-1||i==3){ System.out.print("*"); } else{ System.out.print(" "); } } System.out.println(); } } }
Yaduttam95/Java
A.java
624
import java.io.ByteArrayInputStream; import java.io.DataInputStream; //import java.io.PrintStream; import java.util.Timer; public class h { private static byte[] a; private static int[] b; private static int c; private static int d; // private static Player e; // private static StopTimeControl f; // private static Player g; // private static StopTimeControl h; // private static Sound[] i; private static Timer j = new Timer(); public static final String[] k = { "audio/midi", "audio/x-wav" }; public static void a(DataInputStream paramDataInputStream) throws Exception { int m = paramDataInputStream.readByte(); int i2 = m; do { i2--; int n = paramDataInputStream.readByte(); System.out.println("type = " + n); int i1; byte[] arrayOfByte; switch (n) { case 0: case 1: i1 = paramDataInputStream.readInt(); arrayOfByte = new byte[i1]; paramDataInputStream.readFully(arrayOfByte); // ByteArrayInputStream localByteArrayInputStream = new ByteArrayInputStream(arrayOfByte); if (n == 0) { System.out.println("midi file.."); // e = Manager.createPlayer(localByteArrayInputStream, k[n]); // e.realize(); // e.prefetch(); System.out.println("loaded midi file " + i1); } else { // g = Manager.createPlayer(localByteArrayInputStream, k[n]); // g.realize(); // g.prefetch(); } break; case 2: int i4 = paramDataInputStream.readByte(); //i = new Sound[i4]; for (int i5 = 0; i5 < i4; i5++) { i1 = paramDataInputStream.readInt(); arrayOfByte = new byte[i1]; paramDataInputStream.readFully(arrayOfByte); // i[i5] = new Sound(arrayOfByte, 1); } } } while (i2 > 0); c = paramDataInputStream.readShort(); a = new byte[c]; paramDataInputStream.readFully(a); b = new int[c << 1]; for (int i3 = 0; i3 < c; i3++) { b[(i3 << 1)] = paramDataInputStream.readInt(); b[((i3 << 1) + 1)] = paramDataInputStream.readInt(); } } public static void a(int paramInt1, int paramInt2) throws Exception { int m = a[paramInt1]; if (m == -1) return; if (m == 2) { // i[b[(paramInt1 << 1)]].play(paramInt2); return; } // Player localPlayer = e; // StopTimeControl localStopTimeControl = f; switch (m) { case 1: // localPlayer = g; // localStopTimeControl = h; } // if (localPlayer.getState() == 400) // if ((d == 1) && (paramInt1 != 1)) // localPlayer.stop(); // else // return; d = paramInt1; // localPlayer.setMediaTime(b[(paramInt1 << 1)]); System.out.println("start time = " + b[(paramInt1 << 1)]); int n = b[(paramInt1 << 1)]; int i1 = b[((paramInt1 << 1) + 1)]; System.out.println("end time = " + i1); // j.schedule(new k(localPlayer), (i1 - n) / 1000); // localPlayer.start(); } } /* Location: /Users/ilya/4fun/Biplanes/Bluetooth_Biplanes.jar * Qualified Name: h * JD-Core Version: 0.6.2 */
TheRealPinkie/BT_Biplanes_src
h.java
625
public final class i { public static boolean a; public static final int[] b = { 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, -10, -11, -13, -12, -20, -21, -1, -2, -3, -4, -6, -7, -5, 42, 35 }; private static final int[][] c = { { 0 }, { 1 }, { 2, 10 }, { 3 }, { 4, 12 }, { 5, 14 }, { 6, 13 }, { 7 }, { 8, 11 }, { 9 }, { 10, 20 }, { 11, 21 }, { 12, 19 }, { 13 }, { 15 }, { 16 }, { 10, 20 }, { 11, 21 }, { 12, 19 }, { 13 }, { 15 }, { 16 }, { 14 }, { 17 }, { 18, 14 } }; public static boolean[] d = new boolean[22]; private static int e = 0; private static int f = 0; private static int[] g = new int[20]; private static int[] d(int paramInt) { for (int i = 0; i < b.length; i++) if (paramInt == b[i]) return c[i]; return null; } public static void a(int paramInt) { int[] arrayOfInt = d(paramInt); if (arrayOfInt != null) for (int i = 0; i < arrayOfInt.length; i++) { int j = arrayOfInt[i]; e(j); d[j] = true; } a = true; } private static void e(int paramInt) { g[(f++)] = paramInt; if (f >= 20) f = 0; if (f == e) { e += 1; if (e >= 20) e = 0; } } public static void b(int paramInt) { a = false; int[] arrayOfInt = d(paramInt); if (arrayOfInt == null) return; for (int i = 0; i < arrayOfInt.length; i++) { int j = arrayOfInt[i]; if (d[j] != false) d[j] = false; } } public static boolean c(int paramInt) { return d[paramInt]; } public static int a() { if (e == f) return -66; int i = g[(e++)]; if (e >= 20) e = 0; return i; } public static void b() { int i = 22; do { i--; d[i] = false; } while (i > 0); a = false; } } /* Location: /Users/ilya/4fun/Biplanes/Bluetooth_Biplanes.jar * Qualified Name: i * JD-Core Version: 0.6.2 */
TheRealPinkie/BT_Biplanes_src
i.java
630
import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; import java.nio.file.StandardOpenOption; public class m { public static void main(String[] args) throws IOException { byte[] bytes = Files.readAllBytes(Paths.get(new File("C:\\Users\\user\\workspace_arm\\JavaSTM32\\HelloWorld.class").toURI())); StringBuilder sb = new StringBuilder(); for (byte b : bytes) { sb.append(String.format("0x%02X", b)); sb.append(", "); } Files.write(Paths.get(new File("array.txt").toURI()), sb.toString().getBytes(), StandardOpenOption.CREATE); System.out.println("Array is generated"); } }
Cr0s/JavaSTM32
m.java
632
import java.io.*; import java.util.*; public class e { /** * @param args */ public static void main(String[] args) throws IOException { Scanner in = new Scanner(System.in); int numCases = in.nextInt(); String cmd; int cowID, revertIndex; ArrayList <ArrayList<Integer>> time = new ArrayList(); ArrayList <Integer> timeIndex = new ArrayList(); ArrayList <Integer> cows = new ArrayList(); for(int i = 0; i < numCases; i++) { //System.out.println("INDEX: " + (i)); //String blank = in.next(); cmd = in.next(); //System.out.println(cmd); if(cmd.equals("a")) { //System.out.println("adding"); cowID = in.nextInt(); cows.add(cowID); } else if(cmd.equals("s")) { //System.out.println("removing"); if(cows.size() > 0) cows.remove(cows.size()-1); else { //System.out.println("-1"); //break; } } else if(cmd.equals("t")) { revertIndex = in.nextInt(); cows = new ArrayList<Integer>(); revert(cows, time, revertIndex); } else{} //should never go here //System.out.println(cmd + " " + cowID); //System.out.println("COWS: " + cows); //System.out.println("COW SIZE: " + cows.size()); ArrayList<Integer> newTime = new ArrayList(cows); time.add(newTime); //System.out.println("timeAL" + time); if(cows.size() == 0) System.out.println("-1"); if(cows.size() > 0) System.out.println(cows.get(cows.size()-1)); //else System.out.println("-1"); } } public static void revert(ArrayList <Integer> cows, ArrayList <ArrayList<Integer>> time, int revertIndex) { //System.out.println(" time: " + ((time.get(revertIndex-2)).toString())); ArrayList<Integer> newTime = new ArrayList(time.get(revertIndex-2)); for(int i = 0; i < newTime.size(); i++) { cows.add(newTime.get(i)); } } }
isabelacmor/programmingteam
e.java
633
import java.util.Arrays; import java.util.Scanner; public class A { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int [] data = new int[10]; int cases = sc.nextInt(); int num = sc.nextInt(); for(int i = 0; i<cases; i++) { for (int c = 0; c < 10; c++) { data[c] = sc.nextInt(); } Arrays.sort(data); System.out.print(num + " "); System.out.print(data[7]); num = sc.nextInt(); System.out.println(); } } }
isabelacmor/programmingteam
A.java
635
class h { public static void main(String[] args) { int k = 1; for (int l = 0; l < k; l++) { for (int i = 0; i < 10; i++) { System.out.println(l * i); } } } }
shreyash14s/Translator
h.java
636
public class d { public static void main(String[] args) { final int a = 1; for(int i=0;i<10;i++) { System.out.println(i); } } }
shreyash14s/Translator
d.java
640
import java.awt.Canvas; import java.awt.Color; import java.awt.Font; import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.image.BufferStrategy; import java.util.Random; import javax.swing.JApplet; public class M extends JApplet implements Runnable, MouseListener, KeyListener { MouseEvent click = null; boolean key[] = new boolean[65535]; BufferStrategy strategy; Random r = new Random(); static String n(int p) { return new String(new char[] { (char) ('A' + (p + 5) % 7), new char[] {'u','e','y','o','i'}[(p + 2) % 5], (char) ('k' + (p / 3) % 4), new char[] {'u','e','i','o','a'}[(p / 2 + 1) % 5], (char) ('p' + (p / 2) % 9) }) + new String[] { " I", " II", " III", " IV", " V", " VI" }[(p / 4 + 3) % 6]; } @Override public void init() { setIgnoreRepaint(true); Canvas canvas = new Canvas(); add(canvas); canvas.setBounds(0, 0, 712, 600); canvas.createBufferStrategy(2); strategy = canvas.getBufferStrategy(); canvas.addMouseListener(this); canvas.addKeyListener(this); new Thread(this).start(); } String[] a_names = { "Explore", "build Outpost", "Colonise", "Tax", "improve Defences", "trAde", "Raid", "Invade", "build Warship", "develop advanced fuels", "develop terraforming", "develop cloaking device", "develop advanced economics", "develop advanced weapons", "develop long-range scanners", "build transcendence device" //"get max income", //"smartinvade", //"upgrade planets if needed" }; int[] ai = { 15, // transcend 10, // terraform 12, // adv econ 13, // adv weap 9, // adv fuels 11, // cloak 14, // scanners 24, // defences 0, // explore 17, // smart invade 2, // colonise 8, // warship 1, // outpost 16, // income -1 // guard }; int[] a_shortcuts = { KeyEvent.VK_E, KeyEvent.VK_O, KeyEvent.VK_C, KeyEvent.VK_T, KeyEvent.VK_D, KeyEvent.VK_A, KeyEvent.VK_R, KeyEvent.VK_I, KeyEvent.VK_W }; boolean doAction(int a) { if (allowed(a) && e_money[selE] + value(a) >= 0) { e_msg_fromto[selE][selE] = ""; e_money[selE] += value(a); goback: while(true) { switch (a) { // Skip turn case -1: break; // Explore case 0: p_explored[selP][selE] = true; e_msg_fromto[selE][selE] = "You explore " + n(selP) + " (" + s_names[p_special[selP]] + ", " + e_names[p_owner[selP]] + ")"; break; // Outpost case 1: p_owner[selP] = selE; p_out[selP] = true; p_defence[selP] = 1; break; // Colony case 2: p_owner[selP] = selE; p_out[selP] = false; if (p_special[selP] == 5) { // Warships e_ships[selE]++; } if (p_special[selP] == 6) { // Defensible p_defence[selP] += 2; } if (p_special[selP] == 4) { String what = " nothing of interest"; int option = r.nextInt(6); opts: for (int o = option; o < option + 6; o++) { switch (o % 6) { case 0: // Advanced Fuels if (e_range[selE] == 5) { e_range[selE] = 10; what = " advanced fuel technology"; break opts; } case 1: // Terraforming if (!e_terraform[selE]) { e_terraform[selE] = true; what = " terraforming technology"; break opts; } case 2: // Cloak if (!e_cloak[selE]) { e_cloak[selE] = true; what = " cloaking technology"; break opts; } case 3: // Economics if (e_econBonus[selE] == 0) { e_econBonus[selE] = 1; what = " advanced economics textbooks"; break opts; } case 4: // Weapons if (e_gunBonus[selE] == 0) { e_gunBonus[selE] = 1; what = " advanced weapons technology"; break opts; } // Scanners case 5: if (!e_scanner[selE]) { e_scanner[selE] = true; for (int p = 0; p < 24; p++) { p_explored[p][selE] = true; } what = " detailed planetary charts"; break opts; } }} e_msg_fromto[selE][selE] = "You discover" + what + " on " + n(selP); } break; // Raid case 6: e_msg_fromto[selE][p_owner[selP]] = e_names[selE] + " raids " + n(selP) + " for $" + p_money[selP]; // Tax, Raid case 3: p_money[selP] = 0; break; // Improve Defences default: case 4: p_defence[selP] += 4; break; // Trade case 5: e_money[p_owner[selP]] += p_money[selP]; e_msg_fromto[selE][p_owner[selP]] = e_names[selE] + " trades with you for $" + p_money[selP]; p_money[selP] = 0; break; // Invade case 17: case 7: int victim = p_owner[selP]; e_msg_fromto[selE][victim] = n(selP) + " is invaded by " + e_names[selE] + ", taking $" + p_money[selP]; int def = p_defence[selP] * 3 / 4; if (e_f_pos[victim] == selP) { def += e_ships[victim]; e_ships[victim] = e_ships[victim] / 2; p_owner[selP] = selE; // Find a haven for them. for (int p = 0; p < 24; p++) { if (p_owner[p] == victim) { e_f_pos[victim] = p; e_msg_fromto[selE][victim] += ". Your ships fled to " + n(p); break; } } } p_owner[selP] = selE; p_defence[selP] = p_defence[selP] * 3 / 4; int shipsLost = def - e_ships[selE] / 3; e_msg_fromto[selE][selE] = "You invade " + n(selP) + ", taking " + p_money[selP] + "$"; e_money[selE] += p_money[selP]; p_money[selP] = 0; if (shipsLost > 0) { if (shipsLost > e_ships[selE] / 2) { shipsLost = e_ships[selE] / 2; } e_ships[selE] -= shipsLost; e_msg_fromto[selE][selE] += " and losing " + shipsLost + " warships"; } e_f_pos[selE] = selP; break; // Build Warship case 8: e_ships[selE]++; break; // Advanced Fuels case 9: e_range[selE] = 10; break; // Terraforming case 10: e_terraform[selE] = true; break; // Cloak case 11: e_cloak[selE] = true; break; // Economics case 12: e_econBonus[selE]++; break; // Weapons case 13: e_gunBonus[selE]++; break; // Scanners case 14: e_scanner[selE] = true; for (int p = 0; p < 24; p++) { p_explored[p][selE] = true; } break; // Transcend case 15: e_transcend[selE] = true; break; // Max money case 16: if (p_owner[selP] == selE) { a = 3; // tax } else { a = e_cloak[selE] ? 6 : 5; // Raid if possible, otherwise trade } continue goback; // GOTO! WHEEE! } break; } // This essentially implements goto. Yes, cry. Cry now. // HAVE THEY WON OR LOST? for (int e = 1; e < 5; e++) { e_lost[e] = true; for (int p = 0; p < 24; p++) { if (p_owner[p] == e) { e_lost[e] = false; } } if (!e_lost[e]) { e_won[e] = true; for (int p = 0; p < 24; p++) { if (p_owner[p] != e && p_owner[p] != 0) { e_won[e] = false; } } if (e_transcend[e]) { e_won[e] = true; } } } if (!e_won[selE]) { // END TURN for (int p = 0; p < 24; p++) { if (p_owner[p] != 0 && !p_out[p]) { int money = 2; switch (p_special[p]) { // Rich case 2: money = 3; break; // Poor case 3: money = 1; } p_money[p] += (money + e_econBonus[p_owner[p]]); } } e_p_sel[selE] = selP; selE++; if (selE == 5) { selE = 1; } selP = e_p_sel[selE]; // Clear outbox for (int i = 0; i < 5; i++) { e_msg_fromto[selE][i] = selE == i ? e_msg_fromto[selE][i] : ""; } antechamber = needAntechamber(); // Stipend! //if (!e_human[selE]) { e_money[selE] += 50; } } return true; } return false; } boolean allowed(int a) { switch (a) { // Skip case -1: return true; // Explore case 0: return inRange() && !p_explored[selP][selE]; // Outpost case 1: return inRange() && p_explored[selP][selE] && p_owner[selP] == 0; // Colony case 2: return inRange() && p_explored[selP][selE] && (p_owner[selP] == 0 || (p_owner[selP] == selE && p_out[selP])) && (p_special[selP] != 0 || e_terraform[selE]); // Tax, Improve Defences case 3: case 4: return p_owner[selP] == selE; // Raid case 6: if (!e_cloak[selE] || e_ships[selE] == 0) { return false; } // NO BREAK // Trade case 5: if (p_out[selP]) { return false; } // NO BREAK // Invade case 7: return inRange() && p_explored[selP][selE] && p_owner[selP] != selE && p_owner[selP] != 0 && (a != 7 || e_ships[selE] > 0); // Advanced Fuels case 9: return e_range[selE] == 5; // Terraforming case 10: return !e_terraform[selE]; // Cloak case 11: return !e_cloak[selE]; // Economics case 12: return e_econBonus[selE] < 3; // Weapons case 13: return e_gunBonus[selE] < 3; // Scanners case 14: return !e_scanner[selE]; // Transcend, Build Warship, Get Max Income case 8: case 15: case 16: return true; // Smart invade case 17: /*int p2 = selP; int best = -1; for (selP = 0; selP < 24; selP++) { if (allowed(7) && (best == -1 || p_money[selP] > p_money[best]) && e_money[selE] + value(7) >= 0) { best = selP; } } selP = best; if (best != -1) { return true; } selP = p2; return false;*/ int p2 = selP; int best = -1; int bestV = 0; for (selP = 0; selP < 24; selP++) { if (!allowed(7)) { continue; } int v = 300 + p_money[selP] * 3 + value(7) + p_defence[selP] * 20; int losses = (p_defence[selP] + (e_f_pos[p_owner[selP]]) == selP ? e_ships[p_owner[selP]] : 0) - e_ships[selE] / 3; int newFleet = e_ships[selE]; int enFleet = e_f_pos[p_owner[selP]] == selP ? e_ships[p_owner[selP]] / 2 : e_ships[p_owner[selP]]; if (losses > 0) { v -= losses * 80; newFleet -= losses; } if (e_f_pos[p_owner[selP]] == selP) { v += e_ships[p_owner[selP]] * 40; } // Will it blend / can we hold it? if (newFleet + p_defence[selP] / 2 <= enFleet * 4 / 3) { v = 0; } if (v > bestV && e_money[selE] + value(7) >= 0) { best = selP; bestV = v; } } selP = best; if (best != -1) { int losses = (p_defence[selP] + (e_f_pos[p_owner[selP]]) == selP ? e_ships[p_owner[selP]] : 0) - e_ships[selE] / 3; return true; } selP = p2; return false; // Upgrade planetary defences if needed default: int maxShips = 0; for (int e = 1; e < 5; e++) { if (e != selE && e_ships[e] > maxShips) { maxShips = e_ships[e]; } } for (int p = 0; p < 24; p++) { if (p_owner[p] == selE && p_defence[p] < maxShips + (a - 20)) { int pp = selP; selP = p; if (e_money[selE] + value(4) >= 0) { return true; } else { selP = pp; } } } return false; } } boolean inRange() { for (int p2 = 0; p2 < 24; p2++) { if (p_owner[p2] == selE && ((p_x[p2] - p_x[selP]) * (p_x[p2] - p_x[selP]) + (p_y[p2] - p_y[selP]) * (p_y[p2] - p_y[selP])) <= e_range[selE] * e_range[selE]) { return true; } } return false; } int value(int a) { if (a > 19) { a = 4; } // All 20x are improve defences switch (a) { // Skip turn case -1: return 0; // Explore case 0: return -10; // Outpost case 1: return -30; // Colony case 2: return (e_terraform[selE] || p_special[selP] == 1) ? -70 : -140; // Get Max Income: This actually selects the correct planet as a side-effect case 16: int pp = selP; int best = -1; for (selP = 0; selP < 24; selP++) { if (inRange() && (best == -1 || // Prefer raid > tax > trade (p_owner[selP] == selE ? 3 : e_cloak[selE] ? 5 : 2) * p_money[selP] > (p_owner[best] == selE ? 3 : e_cloak[selE] ? 5 : 2) * p_money[best]) && p_owner[selP] != 0) { best = selP; } } if (best == -1) { selP = pp; return 0; } selP = best; // Tax, trade, raid case 3: case 5: case 6: return p_money[selP]; // Improve Defences case 4: return -60 - 10 * p_defence[selP]; // Invade case 17: case 7: return -50 - Math.max(0, ( p_defence[selP] * 2 + (e_f_pos[selE] == selP ? e_ships[p_owner[selP]] * (2 + e_gunBonus[p_owner[selP]]): 0) - (e_ships[selE] * (2 + e_gunBonus[selE])) ) * 50); // Build Warship case 8: return -60; // Tech: Econ case 12: return new int[] { -400, -1600, -4800, -1 }[e_econBonus[selE]]; // Tech: Guns case 13: return new int[] { -400, -1200, -3600, -1 }[e_gunBonus[selE]]; // Transcendence Device case 15: return -32000; // Tech default: return -400; } } String[] s_names = { "Barren", "Fertile", "Rich", "Poor", "Ancient Artefacts", "Ancient Warship", "Defensible" }; String[] e_names = { "Uninhabited", "Brown", "Red", "Blue", "Green" }; // Empires have an e prefix Color[] e_color = { Color.LIGHT_GRAY, new Color(100, 75, 10), new Color(91, 0, 0), new Color(0, 0, 200), new Color(0, 63, 0) }; // Planets have a p prefix int[] p_x = new int[24]; int[] p_y = new int[24]; int[] p_special = new int[24]; int[] p_owner = new int[24]; boolean[][] p_explored = new boolean[24][5]; boolean[] p_out = new boolean[24]; int[] p_money = new int[24]; int[] p_defence = new int[24]; // Game state int selE = 1; int selP = 1; // Empires int[] e_range = { -1, 5, 5, 5, 5 }; int[] e_ships = { -1, 0, 0, 0, 0 }; int[] e_money = { -1, 0, 0, 0, 0 }; int[] e_f_pos = new int[5]; boolean[] e_lost = new boolean[5]; boolean[] e_won = new boolean[5]; int[] e_p_sel = new int[5]; boolean[] e_human = { false, true, false, false, false }; boolean[] e_terraform = { false, false, false, false, true }; boolean[] e_cloak = { false, false, false, true, false }; int[] e_econBonus = { 0, 1, 0, 0, 0 }; int[] e_gunBonus = { 0, 0, 1, 0, 0 }; boolean[] e_scanner = new boolean[5]; boolean[] e_transcend = new boolean[5]; String[][] e_msg_fromto = { {"","","","","",}, {"","","","","",}, {"","","","","",}, {"","","","","",}, {"","","","","",} }; boolean setup = true; boolean antechamber = true; boolean needAntechamber() { int hps = 0; for (int e = 1; e < 5; e++) { if (e_human[e]) { hps++; } } return hps > 1 && e_human[selE]; } public void run() { int p; for (p = 0; p < 24; p++) { search: while (true) { int x = r.nextInt(16); int y = r.nextInt(16); for (int i = 0; i < 24; i++) { if (p_x[i] == x && p_y[i] == y) { continue search; } } p_x[p] = x; p_y[p] = y; p_owner[p] = 0; p_defence[p] = 0; p_special[p] = r.nextInt(7); break; } } for (p = 1; p < 5; p++) { p_owner[p] = p; p_defence[p] = 5; p_explored[p][p] = true; e_money[p] = 200; p_special[p] = 2; e_p_sel[p] = p; e_f_pos[p] = p; } e_f_pos[0] = -1; game: while (true) { try { Thread.sleep(50); } catch (Exception ex) {} Graphics2D g = (Graphics2D) strategy.getDrawGraphics(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setFont(new Font("Helvetica", 0, 11)); if (setup) { if (click != null) { for (int e = 1; e < 5; e++) { if (click.getX() > 200 && click.getX() < 380 && click.getY() > 200 + e * 40 && click.getY() < 230 + e * 40) { e_human[e] = click.getX() < 290; } } if (click.getX() > 100 && click.getX() < 380 && click.getY() > 400 && click.getY() < 430) { setup = false; antechamber = needAntechamber(); } } click = null; g.setColor(Color.BLACK); g.fillRect(0, 0, 712, 600); for (int e = 1; e < 5; e++) { g.setColor(e_color[e]); g.fillRect(100, 200 + e * 40, 80, 30); g.fill3DRect(200, 200 + e * 40, 80, 30, !e_human[e]); g.fill3DRect(300, 200 + e * 40, 80, 30, e_human[e]); g.setColor(Color.GRAY); g.fill3DRect(100, 400, 280, 30, true); g.setColor(Color.WHITE); g.drawString("Start", 110, 415); g.drawString(e_names[e], 110, 215 + e * 40); g.drawString("Human", 210, 215 + e * 40); g.drawString("Computer", 310, 215 + e * 40); } g.drawString("A small space 4X game.", 80, 80); g.drawString("Setup:", 80, 230); g.setFont(g.getFont().deriveFont(48.0f)); g.drawString("Moo4k", 80, 50); strategy.show(); continue; } if (e_lost[selE]) { for (p = 0; p < 24; p++) { p_explored[p][selE] = true; } doAction(-1); continue; } if (!e_won[selE]) { // User input if (antechamber) { if (click != null) { antechamber = false; } } else { if (e_human[selE]) { for (p = 0; p < 9; p++) { if (key[a_shortcuts[p]]) { doAction(p); click = null; continue game; } } if (click != null) { for (p = 0; p < 24; p++) { if (click.getX() / 32 == p_x[p] && click.getY() / 32 == p_y[p]) { selP = p; } } if (click.getX() > 512 && click.getY() < 512) { doAction(click.getY() / 32); click = null; continue; } } } else { while (!e_human[selE] && !e_won[selE]) { ail: for (int a = 0; a < ai.length; a++) { for (int pp = 0; pp < 24; pp++) { selP = pp; if (doAction(ai[a])) { break ail; } } } } } } } click = null; // Drawing g.setColor(e_color[selE]); g.fillRect(0, 0, 712, 600); g.setColor(Color.WHITE); if (e_won[selE]) { g.drawString(e_names[selE] + " has won!", 10, 300); strategy.show(); continue; } if (antechamber) { g.drawString(e_names[selE] + ": Click to continue", 10, 300); strategy.show(); continue; } g.setColor(Color.BLACK); g.fillRect(2, 2, 708, 598); g.setColor(new Color(30, 30, 40)); for (p = 0; p < 24; p++) { if (selE == p_owner[p]) { g.fillOval( p_x[p] * 32 - e_range[selE] * 32 + 16, p_y[p] * 32 - e_range[selE] * 32 + 16, e_range[selE] * 64, e_range[selE] * 64); } } for (p = 0; p < 24; p++) { g.setColor(Color.WHITE); if (p == selP) { g.fillOval(p_x[p] * 32 + 4, p_y[p] * 32 + 4, 24, 24); } g.setColor(p_explored[p][selE] ? e_color[p_owner[p]] : Color.DARK_GRAY); g.fillOval(p_x[p] * 32 + 6, p_y[p] * 32 + 6, 20, 20); if (p_explored[p][selE]) { g.setColor(g.getColor().brighter().brighter()); g.drawArc(p_x[p] * 32 + 2, p_y[p] * 32 + 2, 28, 28, 0, p_defence[p] * 8); g.setColor(Color.LIGHT_GRAY); if (e_f_pos[p_owner[p]] == p) { g.drawArc(p_x[p] * 32, p_y[p] * 32, 32, 32, 180, e_ships[p_owner[p]] * 8); } if (p_out[p]) { g.fillOval(p_x[p] * 32 + 10, p_y[p] * 32 + 10, 12, 12); } else { g.setColor(Color.WHITE); if (p_owner[p] != 0) { g.drawString(p_money[p] + "$", p_x[p] * 32 + 10, p_y[p] * 32 + 18); } } } } g.setColor(Color.WHITE); g.drawString( p_explored[selP][selE] ? n(selP) + ", " + s_names[p_special[selP]] + ", " + p_defence[selP] + " defence" + (e_f_pos[p_owner[selP]] == selP ? ", " + e_ships[p_owner[selP]] + " ships" : "") : "Unexplored Planet", 5, 520); g.drawString(e_money[selE] + "$, " + e_ships[selE] + " warships at " + n(e_f_pos[selE]), 5, 532); // Messagiplex for (int i = 1; i < 5; i++) { g.setColor(e_color[i]); g.fillRect(12, 528 + i * 13, 492, 13); g.setColor(Color.WHITE); g.drawString(e_msg_fromto[i][selE], 20, 538 + i * 13); } g.setColor(e_color[selE]); g.fillRect(512, 0, 200, 600); // Buttons for (int a = 0; a < 16; a++) { if (allowed(a)) { g.setColor(Color.DARK_GRAY); g.fill3DRect(513, a * 32 + 1, 199, 30, true); g.setColor(e_money[selE] + value(a) < 0 ? Color.GRAY : Color.WHITE); g.drawString(a_names[a] + (value(a) >= 0 ? " (+" : " (") + value(a) + "$)", 520, a * 32 + 20); } } strategy.show(); } } public void mouseClicked(MouseEvent e) {} public void mousePressed(MouseEvent e) { click = e; } public void mouseReleased(MouseEvent e) {} public void mouseEntered(MouseEvent e) {} public void mouseExited(MouseEvent e) {} public void keyTyped(KeyEvent e) {} public void keyPressed(KeyEvent e) { key[((KeyEvent) e).getKeyCode()] = true; } public void keyReleased(KeyEvent e) { key[((KeyEvent) e).getKeyCode()] = false; } }
Zarkonnen/moo4k
M.java
641
import java.math.BigInteger; public class e{ public static void main(String[] args){ BigInteger top = BigInteger.ONE; BigInteger bot = BigInteger.ONE; BigInteger temp = BigInteger.ONE; BigInteger temp2 = BigInteger.ONE; BigInteger two = new BigInteger("2"); BigInteger thr = new BigInteger("3"); BigInteger eig = new BigInteger("8"); for(int x = 66;x>2;x-=2){ temp = bot.multiply(new BigInteger(Integer.toString(x+1))).add(top); temp2 = top.multiply(two).add(bot.multiply(new BigInteger(Integer.toString(2*x+1)))); top = temp; bot = temp2; } top = top.multiply(thr).add(bot.multiply(eig)); System.out.println(top+"/"+bot); String done = top.toString(); int sum = 0; for(int x = 0;x<done.length();x++){ sum+=done.charAt(x)-'0'; } System.out.println("SUM = "+sum); } }
hughbzhang/Competitive_Programming
e.java
643
public interface B { int TEST_ID = TestClass.getTestId(); void foo(); void foobar(); default void go(){ System.out.println("B: go"); } static X[] copiesOfX(int n, X x){ X[] out = new X[n]; for(int i = 0; i < n; i++){ out[i] = x; } return out; } static void printXArray(X[] x){ for (X x2 : x) { System.out.println(x2.getId() + " : " + x2.getName()); } } static boolean compareTwoXId(X x1, X x2){ if(x1.getId() == x2.getId()){ return true; } return false; } }
thieryw/java-interface-demo
B.java
644
import java.util.*; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); //对于多个测试用例写个while循环 while (scanner.hasNext()) { int n = scanner.nextInt(); int[] keys = new int[n]; int i = 0; HashMap<Integer, Integer> hashMap = new HashMap<>(n); for(int k=0; k<n; k++) { int key = scanner.nextInt(); int value = scanner.nextInt(); if(hashMap.get(key) == null) { keys[i] = key; i++; hashMap.put(key, value); } else { hashMap.put(key, hashMap.get(key)+value); } } int[] keys2 = new int[i]; for(int k=0; k<i; k++) { keys2[k] = keys[k]; } Arrays.sort(keys2); for(int j=0; j<i; j++) { System.out.println(keys2[j] + " " + hashMap.get(keys2[j])); } } scanner.close(); } }
NjustJiaweihan/NowCoder_HuaWei
8.java
645
package projekt; public class d { public static void main(String[] args) { // TODO Auto-generated method stub switch(3) { case 2: System.out.println("cxc"); case 3: System.out.println("cxcdd"); } System.out.println("cxc"); for (int i = 0; i < 10; i++) { } } }
TSSKDevAcademy1/Adam_luptak_SHAPE_AUTO
d.java
647
class Q1 { static int getArray(int[] currentArrays) { if (currentArrays.length % 2 == 0) return 0; int middleIndex = currentArrays.length / 2; int middleItem = currentArrays[middleIndex]; for (int i = 0; i < currentArrays.length; i++) { if (i != middleIndex && middleItem >= currentArrays[i]) return 0; } return 1; } public static void main(String[] args) { int[] n = { 2, 4, 5, 1, 7, 2, 4}; System.out.println(getArray(n)); } }
frankhn/maharishi-exam-test-practice-exercise
Q1.java
648
import android.content.ContentValues; import com.whatsapp.WAAppCompatActivity; import com.whatsapp.util.Log; import java.io.ByteArrayOutputStream; import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; import java.nio.charset.Charset; import java.util.List; import org.v; import org.whispersystems.Y; import org.whispersystems.aF; import org.whispersystems.at; public class h implements k { public static String h; private static String i; private static final String[] z; private String a; private String b; private String c; public List d; private int e; private boolean f; private s g; private m j; private String a(List list) { boolean z = m.e; int size = list.size(); if (size > 1) { StringBuilder stringBuilder = new StringBuilder(); for (String append : list) { stringBuilder.append(append).append(";"); if (z) { break; } } size = stringBuilder.length(); if (size > 0) { try { if (stringBuilder.charAt(size - 1) == ';') { return stringBuilder.substring(0, size - 1); } } catch (ArrayIndexOutOfBoundsException e) { throw e; } } return stringBuilder.toString(); } else if (size != 1) { return ""; } else { try { return (String) list.get(0); } catch (ArrayIndexOutOfBoundsException e2) { throw e2; } } } public static byte[] a(byte[] bArr) { boolean z = m.e; if (bArr == null) { return null; } ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); int i = 0; while (i < bArr.length) { byte b = bArr[i]; if (b == 61) { i++; try { int a = a(bArr[i]); i++; byteArrayOutputStream.write((char) ((a << 4) + a(bArr[i]))); } catch (Throwable e) { throw new n(z[11], e); } } byteArrayOutputStream.write(b); i++; if (z) { break; } } return byteArrayOutputStream.toByteArray(); } /* JADX WARNING: inconsistent code. */ /* Code decompiled incorrectly, please refer to instructions dump. */ public void b(java.lang.String r4) { /* r3 = this; r0 = r3.a; Catch:{ ArrayIndexOutOfBoundsException -> 0x002a } if (r0 == 0) goto L_0x0012; L_0x0004: r0 = r3.a; Catch:{ ArrayIndexOutOfBoundsException -> 0x002c } r1 = z; Catch:{ ArrayIndexOutOfBoundsException -> 0x002c } r2 = 9; r1 = r1[r2]; Catch:{ ArrayIndexOutOfBoundsException -> 0x002c } r0 = r0.equalsIgnoreCase(r1); Catch:{ ArrayIndexOutOfBoundsException -> 0x002c } if (r0 == 0) goto L_0x001d; L_0x0012: r0 = r3.j; Catch:{ ArrayIndexOutOfBoundsException -> 0x002e } r0 = r0.d; Catch:{ ArrayIndexOutOfBoundsException -> 0x002e } r0.add(r4); Catch:{ ArrayIndexOutOfBoundsException -> 0x002e } r0 = m.e; Catch:{ ArrayIndexOutOfBoundsException -> 0x002e } if (r0 == 0) goto L_0x0026; L_0x001d: r0 = r3.j; Catch:{ ArrayIndexOutOfBoundsException -> 0x002e } r0 = r0.b; Catch:{ ArrayIndexOutOfBoundsException -> 0x002e } r1 = r3.a; Catch:{ ArrayIndexOutOfBoundsException -> 0x002e } r0.put(r1, r4); Catch:{ ArrayIndexOutOfBoundsException -> 0x002e } L_0x0026: r0 = 0; r3.a = r0; return; L_0x002a: r0 = move-exception; throw r0; Catch:{ ArrayIndexOutOfBoundsException -> 0x002c } L_0x002c: r0 = move-exception; throw r0; Catch:{ ArrayIndexOutOfBoundsException -> 0x002e } L_0x002e: r0 = move-exception; throw r0; */ throw new UnsupportedOperationException("Method not decompiled: h.b(java.lang.String):void"); } public void e(String str) { this.a = str; } public void d() { } public void a() { ((s) this.d.get(this.e)).a = 0; while (this.e > 0) { this.e--; if (((s) this.d.get(this.e)).a == 1) { break; } } this.g = (s) this.d.get(this.e); } private String a(String str, String str2) { try { if (this.c.equalsIgnoreCase(str2)) { return str; } ByteBuffer encode = Charset.forName(this.c).encode(str); byte[] bArr = new byte[encode.remaining()]; encode.get(bArr); try { return new String(bArr, str2); } catch (UnsupportedEncodingException e) { Log.e(z[0] + str2); return new String(bArr); } } catch (UnsupportedEncodingException e2) { throw e2; } } public h() { this(h, h, false); } public void a(String str) { this.j.h.add(str); } private static int a(byte b) { int digit = Character.digit((char) b, 16); if (digit != -1) { return digit; } try { throw new n(z[10] + b); } catch (ArrayIndexOutOfBoundsException e) { throw e; } } public void c(String str) { this.j.a = str; } public void c() { this.g.c.add(this.j); } public void d(String str) { boolean z = m.e; s sVar = new s(); try { sVar.a = 1; sVar.b = str; this.d.add(sVar); this.e = this.d.size() - 1; this.g = (s) this.d.get(this.e); if (WAAppCompatActivity.c != 0) { m.e = !z; } } catch (ArrayIndexOutOfBoundsException e) { throw e; } catch (ArrayIndexOutOfBoundsException e2) { throw e2; } } public void m1045a(List list) { boolean z = m.e; if (list != null) { try { if (list.size() != 0) { String str; ContentValues contentValues = this.j.b; String str2 = h; String asString = contentValues.getAsString(z[12]); if (str2 != null) { try { if (str2.length() != 0) { str = str2; for (String str22 : list) { this.j.f.add(a(str22, str, asString)); if (z) { break; } } this.j.c = a(this.j.f); return; } } catch (ArrayIndexOutOfBoundsException e) { throw e; } } str = this.b; while (r4.hasNext()) { this.j.f.add(a(str22, str, asString)); if (z) { break; this.j.c = a(this.j.f); return; } } this.j.c = a(this.j.f); return; } } catch (ArrayIndexOutOfBoundsException e2) { throw e2; } } this.j.g = null; this.j.f.clear(); this.j.f.add(""); this.j.c = ""; } public void e() { this.j = new m(); } /* JADX WARNING: inconsistent code. */ /* Code decompiled incorrectly, please refer to instructions dump. */ public h(java.lang.String r3, java.lang.String r4, boolean r5) { /* r2 = this; r0 = m.e; r2.<init>(); r1 = new java.util.ArrayList; r1.<init>(); r2.d = r1; r1 = 0; r2.e = r1; if (r3 == 0) goto L_0x0015; L_0x0011: r2.c = r3; Catch:{ ArrayIndexOutOfBoundsException -> 0x0026 } if (r0 == 0) goto L_0x0019; L_0x0015: r1 = h; Catch:{ ArrayIndexOutOfBoundsException -> 0x0026 } r2.c = r1; Catch:{ ArrayIndexOutOfBoundsException -> 0x0026 } L_0x0019: if (r4 == 0) goto L_0x001f; L_0x001b: r2.b = r4; Catch:{ ArrayIndexOutOfBoundsException -> 0x0028 } if (r0 == 0) goto L_0x0023; L_0x001f: r0 = h; Catch:{ ArrayIndexOutOfBoundsException -> 0x0028 } r2.b = r0; Catch:{ ArrayIndexOutOfBoundsException -> 0x0028 } L_0x0023: r2.f = r5; return; L_0x0026: r0 = move-exception; throw r0; L_0x0028: r0 = move-exception; throw r0; */ throw new UnsupportedOperationException("Method not decompiled: h.<init>(java.lang.String, java.lang.String, boolean):void"); } /* JADX WARNING: inconsistent code. */ /* Code decompiled incorrectly, please refer to instructions dump. */ private java.lang.String a(java.lang.String r12, java.lang.String r13, java.lang.String r14) { /* r11 = this; r9 = 10; r3 = 0; r4 = m.e; if (r14 == 0) goto L_0x016b; L_0x0007: r0 = z; Catch:{ UnsupportedEncodingException -> 0x0029 } r1 = 4; r0 = r0[r1]; Catch:{ UnsupportedEncodingException -> 0x0029 } r0 = r14.equals(r0); Catch:{ UnsupportedEncodingException -> 0x0029 } if (r0 != 0) goto L_0x001b; L_0x0012: r0 = "B"; r0 = r14.equals(r0); Catch:{ UnsupportedEncodingException -> 0x002b } if (r0 == 0) goto L_0x002f; L_0x001b: r0 = r11.j; Catch:{ UnsupportedEncodingException -> 0x002d } r1 = r12.getBytes(); Catch:{ UnsupportedEncodingException -> 0x002d } r2 = 0; r1 = android.backport.util.Base64.decode(r1, r2); Catch:{ UnsupportedEncodingException -> 0x002d } r0.g = r1; Catch:{ UnsupportedEncodingException -> 0x002d } L_0x0028: return r12; L_0x0029: r0 = move-exception; throw r0; Catch:{ UnsupportedEncodingException -> 0x002b } L_0x002b: r0 = move-exception; throw r0; Catch:{ UnsupportedEncodingException -> 0x002d } L_0x002d: r0 = move-exception; throw r0; L_0x002f: r0 = z; r1 = 2; r0 = r0[r1]; r0 = r14.equals(r0); if (r0 == 0) goto L_0x016b; L_0x003a: r0 = z; r1 = 3; r0 = r0[r1]; r1 = " "; r0 = r12.replaceAll(r0, r1); r1 = z; r2 = 7; r1 = r1[r2]; r2 = "\t"; r5 = r0.replaceAll(r1, r2); r0 = r11.f; if (r0 == 0) goto L_0x0061; L_0x0056: r0 = z; r1 = 6; r0 = r0[r1]; r0 = r5.split(r0); if (r4 == 0) goto L_0x00c7; L_0x0061: r0 = new java.lang.StringBuilder; r0.<init>(); r6 = r5.length(); r7 = new java.util.ArrayList; r7.<init>(); r1 = r3; L_0x0070: if (r1 >= r6) goto L_0x00b2; L_0x0072: r8 = r5.charAt(r1); if (r8 != r9) goto L_0x0182; L_0x0078: r0 = r0.toString(); r7.add(r0); r0 = new java.lang.StringBuilder; r0.<init>(); if (r4 == 0) goto L_0x00ae; L_0x0086: r2 = r0; L_0x0087: r0 = 13; if (r8 != r0) goto L_0x017e; L_0x008b: r0 = r2.toString(); r7.add(r0); r2 = new java.lang.StringBuilder; r2.<init>(); r0 = r6 + -1; if (r1 >= r0) goto L_0x017b; L_0x009b: r0 = r1 + 1; r0 = r5.charAt(r0); if (r0 != r9) goto L_0x0178; L_0x00a3: r0 = r1 + 1; L_0x00a5: if (r4 == 0) goto L_0x0174; L_0x00a7: r1 = r2; L_0x00a8: r1.append(r8); Catch:{ UnsupportedEncodingException -> 0x0122 } r10 = r0; r0 = r1; r1 = r10; L_0x00ae: r1 = r1 + 1; if (r4 == 0) goto L_0x0070; L_0x00b2: r0 = r0.toString(); r1 = r0.length(); Catch:{ UnsupportedEncodingException -> 0x0124 } if (r1 <= 0) goto L_0x00bf; L_0x00bc: r7.add(r0); Catch:{ UnsupportedEncodingException -> 0x0124 } L_0x00bf: r0 = new java.lang.String[r3]; r0 = r7.toArray(r0); r0 = (java.lang.String[]) r0; L_0x00c7: r5 = new java.lang.StringBuilder; r5.<init>(); r6 = r0.length; r2 = r3; L_0x00ce: if (r2 >= r6) goto L_0x00ec; L_0x00d0: r1 = r0[r2]; r7 = "="; r7 = r1.endsWith(r7); if (r7 == 0) goto L_0x00e5; L_0x00db: r7 = r1.length(); r7 = r7 + -1; r1 = r1.substring(r3, r7); L_0x00e5: r5.append(r1); r1 = r2 + 1; if (r4 == 0) goto L_0x0171; L_0x00ec: r0 = r5.toString(); Catch:{ UnsupportedEncodingException -> 0x0126 } r1 = r11.c; Catch:{ UnsupportedEncodingException -> 0x0126 } r0 = r0.getBytes(r1); Catch:{ UnsupportedEncodingException -> 0x0126 } L_0x00f6: r0 = a(r0); Catch:{ n -> 0x014c } r12 = new java.lang.String; Catch:{ UnsupportedEncodingException -> 0x0101 } r12.<init>(r0, r13); Catch:{ UnsupportedEncodingException -> 0x0101 } goto L_0x0028; L_0x0101: r1 = move-exception; r1 = new java.lang.StringBuilder; r1.<init>(); r2 = z; r3 = 1; r2 = r2[r3]; r1 = r1.append(r2); r1 = r1.append(r13); r1 = r1.toString(); com.whatsapp.util.Log.e(r1); r12 = new java.lang.String; r12.<init>(r0); goto L_0x0028; L_0x0122: r0 = move-exception; throw r0; L_0x0124: r0 = move-exception; throw r0; L_0x0126: r0 = move-exception; r0 = new java.lang.StringBuilder; r0.<init>(); r1 = z; r2 = 8; r1 = r1[r2]; r0 = r0.append(r1); r1 = r11.c; r0 = r0.append(r1); r0 = r0.toString(); com.whatsapp.util.Log.e(r0); r0 = r5.toString(); r0 = r0.getBytes(); goto L_0x00f6; L_0x014c: r0 = move-exception; r1 = new java.lang.StringBuilder; r1.<init>(); r2 = z; r3 = 5; r2 = r2[r3]; r1 = r1.append(r2); r0 = r1.append(r0); r0 = r0.toString(); com.whatsapp.util.Log.e(r0); r12 = ""; goto L_0x0028; L_0x016b: r12 = r11.a(r12, r13); goto L_0x0028; L_0x0171: r2 = r1; goto L_0x00ce; L_0x0174: r1 = r0; r0 = r2; goto L_0x00ae; L_0x0178: r0 = r1; goto L_0x00a5; L_0x017b: r0 = r2; goto L_0x00ae; L_0x017e: r0 = r1; r1 = r2; goto L_0x00a8; L_0x0182: r2 = r0; goto L_0x0087; */ throw new UnsupportedOperationException("Method not decompiled: h.a(java.lang.String, java.lang.String, java.lang.String):java.lang.String"); } public void b() { } static { Object obj = -1; String[] strArr = new String[13]; int i = 0; String[] strArr2 = strArr; String[] strArr3 = strArr; String str = "cR#\u0010BA\u0013>\u0013\u0007@])\u0013C@\tj\u001fODA9\u0019S\u0018"; Object obj2 = -1; while (true) { char[] toCharArray = str.toCharArray(); int length = toCharArray.length; char[] cArr = toCharArray; for (int i2 = 0; length > i2; i2++) { int i3; char c = cArr[i2]; switch (i2 % 5) { case v.m /*0*/: i3 = 37; break; case at.g /*1*/: i3 = 51; break; case at.i /*2*/: i3 = 74; break; case at.o /*3*/: i3 = 124; break; default: i3 = 39; break; } cArr[i2] = (char) (i3 ^ c); } str = new String(cArr).intern(); switch (obj2) { case v.m /*0*/: strArr2[i] = str; str = "tf\u0005(ba\u001e\u001a.nkg\u000b>k`"; i = 2; strArr2 = strArr3; obj2 = 1; break; case at.g /*1*/: strArr2[i] = str; str = "\u0018\u0013"; i = 3; strArr2 = strArr3; obj2 = 2; break; case at.i /*2*/: strArr2[i] = str; i = 4; strArr2 = strArr3; str = "gr\u00199\u0011\u0011"; obj2 = 3; break; case at.o /*3*/: strArr2[i] = str; i = 5; str = "cR#\u0010BA\u0013>\u0013\u0007AV)\u0013C@\u0013;\tHQV.QWWZ$\bFG_/F\u0007"; obj2 = 4; strArr2 = strArr3; break; case at.p /*4*/: strArr2[i] = str; i = 6; str = "(9"; obj2 = 5; strArr2 = strArr3; break; case at.m /*5*/: strArr2[i] = str; i = 7; str = "\u0018:"; obj2 = 6; strArr2 = strArr3; break; case Y.f /*6*/: strArr2[i] = str; i = 8; str = "cR#\u0010BA\u0013>\u0013\u0007@])\u0013C@\tj\u001fODA9\u0019S\u0018"; obj2 = 7; strArr2 = strArr3; break; case aF.v /*7*/: strArr2[i] = str; i = 9; str = "qj\u001a9"; obj2 = 8; strArr2 = strArr3; break; case aF.u /*8*/: strArr2[i] = str; i = 10; str = "l]<\u001dKLWj)ui\u0013/\u0012DJW#\u0012@\u001f\u0013$\u0013S\u0005Rj\nFIZ.\\CLT#\b\u0007\rA+\u0018N]\u0013{J\u000e\u001f\u0013"; obj2 = 9; strArr2 = strArr3; break; case Y.l /*9*/: strArr2[i] = str; i = 11; str = "l]<\u001dKLWj\rRJG/\u0018\nUA#\u0012SDQ&\u0019\u0007@])\u0013CL]-"; obj2 = 10; strArr2 = strArr3; break; case Y.t /*10*/: strArr2[i] = str; i = 12; str = "`}\t3cl}\r"; obj2 = 11; strArr2 = strArr3; break; case Y.j /*11*/: strArr2[i] = str; z = strArr3; String str2 = "sw\u000b(fgF#\u0010C@A"; while (true) { char[] toCharArray2 = str2.toCharArray(); int length2 = toCharArray2.length; char[] cArr2 = toCharArray2; for (int i4 = 0; length2 > i4; i4++) { int i5; char c2 = cArr2[i4]; switch (i4 % 5) { case v.m /*0*/: i5 = 37; break; case at.g /*1*/: i5 = 51; break; case at.i /*2*/: i5 = 74; break; case at.o /*3*/: i5 = 124; break; default: i5 = 39; break; } cArr2[i4] = (char) (i5 ^ c2); } str2 = new String(cArr2).intern(); switch (obj) { case v.m /*0*/: h = str2; return; default: i = str2; str2 = "pg\fQ\u001f"; obj = null; } } default: strArr2[i] = str; str = "cR#\u0010BA\u0013>\u0013\u0007@])\u0013C@\tj\u001fODA9\u0019S\u0018"; i = 1; strArr2 = strArr3; obj2 = null; break; } } } }
GigaDroid/Decompiled-Whatsapp
h.java
649
class Solution { public int[] twoSum(int[] nums, int target) { Map<Integer,Integer> map = new HashMap<>(); for(int i=0;i<nums.length;i++){ int num = nums[i]; if(map.containsKey(target-num)){ return new int[]{map.get(target-num),i}; } map.put(num,i); } return new int[]{0,0}; } }
fztfztfztfzt/leetcode
1.java
650
import java.util.HashMap; class Solution { public int[] twoSum(int[] nums, int target) { HashMap<Integer, Integer> map= new HashMap<>(); for(int i = 0; i < nums.length; i++) { if(map.containsKey(target-nums[i])) { return new int[] {map.get(target-nums[i]), i}; } else { map.put(nums[i], i); } } return new int[] {-1,-1}; } }
kalongn/LeetCode_Solution
1.java
651
class Solution { public boolean isPalindrome(int x) { // String Approach /* String str = "" + x; for (int i = 0; i < str.length() / 2; i++) { if (str.charAt(i) != str.charAt(str.length() - 1 - i)) { return false; } } return true; */ if (x < 0 || (x != 0 && x % 10 == 0)) { return false; } int rev = 0; while (x > rev) { rev = rev * 10 + x % 10; x = x / 10; } return (x == rev || x == rev / 10); } }
kalongn/LeetCode_Solution
9.java
653
import java.util.Scanner; public class text_Problem01 { public static void main(String[] args) { Scanner input = new Scanner(System.in); String str = input.nextLine(); int countLet = 0; int countSym = 0; int countInt = 0; for (int i = 0; i < str.length(); i++) { char strCh = str.charAt(i); if (Character.isDigit(strCh)) { countInt++; } else if (Character.isLetter(strCh)) { countLet++; } else { countSym++; } } if (countInt > countSym) { if (countInt > countLet) { System.out.println("C"); } else { System.out.println("B"); } } else if (countSym > countInt) { if (countSym > countLet) { System.out.println("Z"); } else { System.out.println("B"); } } } }
handball/12052014_bgcoder
1.java
658
import android.content.ContentValues; import com.whatsapp.WAAppCompatActivity; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; import org.v; import org.whispersystems.at; public class m { public static boolean e; private static final String[] z; public String a; public ContentValues b; public String c; public Set d; public List f; public byte[] g; public Set h; static { String[] strArr = new String[7]; String str = "v[!\u0002!*\u0016\u001c\u0011>\u0005/\b \u000b`["; Object obj = -1; String[] strArr2 = strArr; String[] strArr3 = strArr; int i = 0; while (true) { char[] toCharArray = str.toCharArray(); int length = toCharArray.length; char[] cArr = toCharArray; for (int i2 = 0; length > i2; i2++) { int i3; char c = cArr[i2]; switch (i2 % 5) { case v.m /*0*/: i3 = 90; break; case at.g /*1*/: i3 = 123; break; case at.i /*2*/: i3 = 81; break; case at.o /*3*/: i3 = 112; break; default: i3 = 78; break; } cArr[i2] = (char) (i3 ^ c); } str = new String(cArr).intern(); switch (obj) { case v.m /*0*/: strArr2[i] = str; str = "v[!\u0011<;\u0016\u001c\u0011>`["; i = 2; strArr2 = strArr3; obj = 1; break; case at.g /*1*/: strArr2[i] = str; str = "v[!\u0002!*-0\u001c;?$'\u0015-.\u0014#P=3\u00014Jn"; i = 3; strArr2 = strArr3; obj = 2; break; case at.i /*2*/: strArr2[i] = str; str = "*\t>\u0000\u0000;\u00164Jn"; i = 4; strArr2 = strArr3; obj = 3; break; case at.o /*3*/: strArr2[i] = str; i = 5; strArr2 = strArr3; str = "v[!\u0002!*<#\u001f;*(4\u0004tz"; obj = 4; break; case at.p /*4*/: strArr2[i] = str; i = 6; str = "v[!\u0002!*-0\u001c;?Aq"; obj = 5; strArr2 = strArr3; break; case at.m /*5*/: strArr2[i] = str; z = strArr3; return; default: strArr2[i] = str; str = "v[!\u0002!*-0\u001c;?$3\t:?\bq\u0003' \u001ekP"; i = 1; strArr2 = strArr3; obj = null; break; } } } public boolean equals(Object obj) { if (!(obj instanceof m)) { return false; } m mVar = (m) obj; if (this.a == null || !this.a.equals(mVar.a) || !this.b.equals(mVar.b) || !this.d.equals(mVar.d) || !this.h.equals(mVar.h)) { return false; } if (this.g != null && Arrays.equals(this.g, mVar.g)) { return true; } if (!this.c.equals(mVar.c)) { return false; } if (this.f.equals(mVar.f) || this.f.size() == 1 || mVar.f.size() == 1) { return true; } return false; } public void a(String str) { this.d.add(str.toUpperCase()); } public m() { this.a = ""; this.c = ""; this.f = new ArrayList(); this.b = new ContentValues(); this.d = new HashSet(); this.h = new HashSet(); } public String toString() { boolean z = e; StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(z[4]); stringBuilder.append(this.a); stringBuilder.append(z[2]); stringBuilder.append(this.b.toString()); stringBuilder.append(z[0]); stringBuilder.append(this.d.toString()); stringBuilder.append(z[5]); stringBuilder.append(this.h.toString()); if (this.f != null && this.f.size() > 1) { stringBuilder.append(z[3]); stringBuilder.append(this.f.size()); } if (this.g != null) { stringBuilder.append(z[1]); stringBuilder.append(this.g.length); } stringBuilder.append(z[6]); stringBuilder.append(this.c); String stringBuilder2 = stringBuilder.toString(); if (z) { WAAppCompatActivity.c++; } return stringBuilder2; } }
GigaDroid/Decompiled-Whatsapp
m.java
659
//To find the Kth smallest numbe in a given array which means we need to find the element in the array which is at kth position //smallest like the 3rd smallest or the 4th smallest number . public class K { static int smallest(int[] arr , int k){ int count=0 ; int[] sorted = sort(arr) ; return arr[k-1] ; } static int[] sort(int[] arr){ for(int i = 0 ; i < arr.length -1 ; i++){ if(arr[i]>arr[i+1]){ int temp = arr[i] ; arr[i] = arr[i+1] ; arr[i+1] = temp ; } } return arr ; } public static void main(String[] args) { int arr[] = {7, 10, 4, 20, 15}; int min = smallest(arr, 4); System.out.printf("%d th smallest element in the given array is ",4) ; System.out.print(min) ; } }
Akashsri3bi/Data_Structure
K.java
660
class Solution { public int[] twoSum(int[] nums, int target) { Map<Integer, Integer> map = new HashMap<>(); for (int i = 0; i < nums.length; i++) { int complement = target - nums[i]; if (map.containsKey(complement)) { return new int[] { map.get(complement), i }; } map.put(nums[i], i); } return new int[] {-1, -1}; } }
sakaars/codes
TWOSUM
662
/*Expert Level 2 1 3 4 -1 2 1 3 -1 -4 */ import java.io.*; public class B { public static void main(String[] args){ String hello=sequences("2,1,3,4"); System.out.println(hello); } public static String sequences(String input1) { String[] strArray = input1.split(","); int total_length=strArray.length; while(total_length>1) { for(int i=0; i<total_length-1;i++) { strArray[i]=""+(Integer.parseInt(strArray[i+1])-Integer.parseInt(strArray[i])); } total_length--; } return strArray[0]; } }
jmimohsin/Code-Gladiators-2015
B.java
664
//{ Driver Code Starts //Initial Template for Java import java.io.*; import java.util.*; class GFG { public static void main(String args[])throws IOException { BufferedReader read = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(read.readLine()); while(t-- > 0) { int N = Integer.parseInt(read.readLine()); int arr[][] = new int[N][N]; for(int i = 0; i < N; i++) { int k = 0; String str[] = read.readLine().trim().split("\\s+"); for(int j = 0; j < N; j++){ arr[i][j] = Integer.parseInt(str[k]); k++; } } System.out.println(new Solution().columnWithMaxZeros(arr,N)); } } } // } Driver Code Ends //User function Template for Java class Solution { int columnWithMaxZeros(int arr[][], int N) { // code here int max = Integer.MIN_VALUE; int index = -1; for(int i=0; i<arr.length; i++){ int max_local = 0; for(int j =0; j<arr[0].length; j++){ if(arr[j][i] == 0) max_local++; } if(max_local > max){ max = max_local; index = i; } } if(max == 0) return -1; return index; } }
dhruvabhat24/Geeks-4-Geeks_November
9.java
665
import java.io.*; public class s { public void func()throws IOException { int a,b,c=0,d=0,i,j; BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.println("enter two no. for checking whether it is twin prime"); a=Integer.parseInt(br.readLine()); b=Integer.parseInt(br.readLine()); for(i=2;i<a;i++) { if(a%i==0) break; else c=a; } for(j=2;j<b;j++) { if(b%j==0) break; else d=b; } if(c==0||d==0) System.out.println("no. is not twin prime"); else { if(a-b==2||b-a==2) System.out.println("no. is twin prime"); } } }
shikhar29111996/Java-programs
s.java
667
//{ Driver Code Starts // Initial Template for Java // Initial Template for Java import java.util.*; import java.lang.*; import java.io.*; // Position this line where user code will be pasted. class GFG { public static void main(String[] args) throws IOException { BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); PrintWriter out=new PrintWriter(System.out); int T = Integer.parseInt(in.readLine()); while (T-- > 0) { String s[] = in.readLine().trim().split(" "); int n = Integer.parseInt(s[0]); int m = Integer.parseInt(s[1]); int a[][] = new int[n][m]; for (int i = 0; i < n; i++) { s = in.readLine().trim().split(" "); for (int j = 0; j < m; j++) { a[i][j] = Integer.parseInt(s[j]); } } Solution ob = new Solution(); out.println(ob.numberOfEnclaves(a)); } out.close(); } } // } Driver Code Ends // User function Template for Java class Solution { public int numberOfEnclaves(int[][] grid) { int n = grid.length; int m = grid[0].length; for (int i = 0; i < n; i++) { if (grid[i][0] == 1) { dfs(grid, i, 0); } if (grid[i][m - 1] == 1) { dfs(grid, i, m - 1); } } for (int j = 0; j < m; j++) { if (grid[0][j] == 1) { dfs(grid, 0, j); } if (grid[n - 1][j] == 1) { dfs(grid, n - 1, j); } } int count = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (grid[i][j] == 1) { count++; } } } return count; } private void dfs(int[][] grid, int x, int y) { int n = grid.length; int m = grid[0].length; if (x < 0 || x >= n || y < 0 || y >= m || grid[x][y] == 0) { return; } grid[x][y] = 0; dfs(grid, x + 1, y); dfs(grid, x - 1, y); dfs(grid, x, y + 1); dfs(grid, x, y - 1); } }
dhruvabhat24/geek-4-geeks-october
1.java
670
import java.util.*;class W{public static void main(String[]a){(new W()).t();}void p(String k,int i){System.out.print(k+(i<1?"":"\n"));}int[]M;int P;int c(){int m,a,b,i;for(a=b=i=0;i<3;i++){a=M[i*3];b=M[i];m=a==M[i*3+1]&&M[i*3+1]==M[i*3+2]&&a>0?a:b==M[i+3]&&M[i+3]==M[i+6]&&b>0?b:0;if(m>0){return m;}}m=M[4];return M[0]==m&&m==M[8]||b==m&&m==a?m:0;}void g(){for(int i=0;i<9;)p(w(M[i]),i++%3/2);p("",1);}int x(int i){return(new Random()).nextInt(i);}String w(int i){return(i<1)?".":((2*i-3)*P<0)?"X":"O";}int y(){return(new Scanner(System.in)).nextInt();}void Z(){int i;do{i=x(9);}while(!s(i,1));}int o(int a,int b,int c,int z,int x){return a==b&&c==x&&a==z?2:a==x&&b==c&&b==z?0:a==c&&b==x&&c==z?1:-1;}int d(int z,int y,int k){int i=0,j;for(;i<3;i++){if((j=o(M[i*3],M[i*3+1],M[i*3+2],z*k,z*(1-k)))>=0?s(k>0?i*3+j:i*3+2-j/2,y):(j=o(M[i],M[i+3],M[i+6],z*k,z*(1-k)))>=0?s(k>0?i+3*j:i+(2-j/2)*3,y):0>1)return 1;}if((i=o(M[0],M[4],M[8],z*k,z*(1-k)))>=0?s(k>0?i*4:8-(i/2)*4,y):(i=o(M[2],M[4],M[6],z*k,z*(1-k)))>=0?s(k>0?i*2+2:6-(i/2)*2,y):0>1)return 1;return 0;}void z(){if(!(d(1,1,1)>0||d(2,1,1)>0||s(4,1)||d(1,1,0)>0))Z();}boolean s(int i,int z){if(M[i]<1){p(w(z)+" to "+i%3+","+i/3,1);return(M[i]=z)==z;}return 0>1;}void t(){while(1>0){M=new int[9];int m=9,x;if(x(2)<1){P=1;Z();g();m--;}else P=-1;do{do{p("x?",0);x=y();p("y?",0);}while(!s(y()*3+x,2));m--;g();x=c();if(x>0||m<1)break;z();g();m--;x=c();}while(m>0&&x<1);if(x<1)p("No winner!",1);else p(w(x)+" wins!",1);}}}
ProgrammerDan/tic-tac-toe-golf
W.java
672
import java.util.*; public class B { public static void main(String args[]) { Scanner sc=new Scanner(System.in); int x,y; for(x=1;x<=5;x++) { for(y=1;y<=x;y++) { if (y%2==0) { System.out.print("{"); } else { System.out.print("["); } } System.out.println(); } } }
prakhe/basic-java-codes
B.java
673
//{ Driver Code Starts //Initial Template for Java import java.io.*; import java.util.*; class GFG{ public static void main(String args[])throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(in.readLine()); while(t-- > 0){ String arr[] = in.readLine().trim().split("\\s+"); int n = Integer.parseInt(arr[0]); int m = Integer.parseInt(arr[1]); int mat[][] = new int[n][m]; for(int i = 0;i < n;i++){ String a[] = in.readLine().trim().split("\\s+"); for(int j = 0;j < m;j++) mat[i][j] = Integer.parseInt(a[j]); } int q = Integer.parseInt(in.readLine()); int queries[][] = new int[q][3]; for(int i = 0;i < q;i++){ String a1[] = in.readLine().trim().split("\\s+"); for(int j = 0;j < 3;j++) queries[i][j] = Integer.parseInt(a1[j]); } Solution ob = new Solution(); List<Integer> ans = new ArrayList<Integer>(); ans = ob.matrixSum(n, m, mat, q, queries); for(int i = 0;i < q;i++) System.out.println(ans.get(i)); } } } // } Driver Code Ends //User function Template for Java class Solution{ static List<Integer> matrixSum(int n, int m, int mat[][], int q, int queries[][]) { // code here List<Integer> ans = new ArrayList<>(); for (int i = 0; i < q; i++) { int col = queries[i][2]; int row = queries[i][1]; int val = queries[i][0]; int sum = 0; int cs = col - val, rs = row - val + 1, re = row + val, ce = col + val; for (int j = cs; j <= ce && j < m; j++) { if (row - val >= 0 && j < m && j >= 0) { sum += mat[row - val][j]; } if (row + val < n && j < m && j >= 0) { sum += mat[row + val][j]; } } for (int j = rs; j < re && j < n; j++) { if (col - val >= 0 && j < n && j >= 0) { sum += mat[j][col - val]; } if (col + val < m && j < n && j >= 0) { sum += mat[j][col + val]; } } ans.add(sum); } return ans; } }
dhruvabhat24/Geeks-4-Geeks_November
6.java
675
import java.util.*; public class A { public static boolean compare(String s1, String s2) { return s1.charAt(s1.length()-1)==s2.charAt(0); } public static void main(String[] args) { Scanner in = new Scanner(System.in); Set<String> set = new HashSet<String>(); ArrayList<String> r = new ArrayList<String>(); int n = in.nextInt(); String a; for (int i=0;i<n;i++) { a = in.next(); if (set.add(a) == false) { System.out.println((i%2 == 0)? "Player 1 lost":"Player 2 lost"); return; } r.add(a); } int i =0; while(i+1 < n && compare(r.get(i),r.get(i+1))) { i++; } if (i == n - 1) System.out.println("Fair Game"); else if(i % 2 == 0) System.out.println("Player 2 lost"); else if(i%2 == 1) System.out.println("Player 1 lost"); } }
swiftyx/VTHSPC-2017
A.java
679
//{ Driver Code Starts import java.util.*; class Sorted_Array { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int T = sc.nextInt(); while (T > 0) { int n = sc.nextInt(); int arr[] = new int[n]; for (int i = 0; i < n; i++) { arr[i] = sc.nextInt(); } Solution obj = new Solution(); System.out.println(obj.transitionPoint(arr, n)); T--; } } } // } Driver Code Ends class Solution { int transitionPoint(int arr[], int n) { // code here for(int i =0;i<arr.length;i++){ if(arr[i]==1){ return i; } } return -1; } }
dhruvabhat24/Geeks-4-Geeks_November
4.java
680
/** * Comment free (yay) source code for Left 4k Dead by Markus Persson * Please don't reuse any of this code in other projects. * http://www.mojang.com/notch/j4k/l4kd/ */ import java.applet.Applet; import java.awt.*; import java.awt.event.*; import java.awt.image.*; import java.util.*; public class G extends Applet implements Runnable { private boolean[] k = new boolean[32767]; private int m; public void start() { enableEvents(AWTEvent.KEY_EVENT_MASK | AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK); new Thread(this).start(); } public void run() { BufferedImage image = new BufferedImage(240, 240, BufferedImage.TYPE_INT_RGB); Graphics ogr = image.getGraphics(); Random random = new Random(); int[] pixels = ((DataBufferInt) image.getRaster().getDataBuffer()).getData(); int[] sprites = new int[18 * 4 * 16 * 12 * 12]; int pix = 0; for (int i = 0; i < 18; i++) { int skin = 0xFF9993; int clothes = 0xFFffff; if (i > 0) { skin = 0xa0ff90; clothes = (random.nextInt(0x1000000) & 0x7f7f7f); } for (int t = 0; t < 4; t++) { for (int d = 0; d < 16; d++) { double dir = d * Math.PI * 2 / 16.0; if (t == 1) dir += 0.5 * Math.PI * 2 / 16.0; if (t == 3) dir -= 0.5 * Math.PI * 2 / 16.0; // if (i == 17) // { // dir = d * Math.PI * 2 / 64; //} double cos = Math.cos(dir); double sin = Math.sin(dir); for (int y = 0; y < 12; y++) { int col = 0x000000; for (int x = 0; x < 12; x++) { int xPix = (int) (cos * (x - 6) + sin * (y - 6) + 6.5); int yPix = (int) (cos * (y - 6) - sin * (x - 6) + 6.5); if (i == 17) { if (xPix > 3 && xPix < 9 && yPix > 3 && yPix < 9) { col = 0xff0000 + (t & 1) * 0xff00; } } else { if (t == 1 && xPix > 1 && xPix < 4 && yPix > 3 && yPix < 8) col = skin; if (t == 3 && xPix > 8 && xPix < 11 && yPix > 3 && yPix < 8) col = skin; if (xPix > 1 && xPix < 11 && yPix > 5 && yPix < 8) { col = clothes; } if (xPix > 4 && xPix < 8 && yPix > 4 && yPix < 8) { col = skin; } } sprites[pix++] = col; if (col > 1) { col = 1; } else { col = 0; } } } } } } int score = 0; int hurtTime = 0; int bonusTime = 0; int xWin0 = 0; int yWin0 = 0; int xWin1 = 0; int yWin1 = 0; restart: while (true) { boolean gameStarted = false; int level = 0; int shootDelay = 0; int rushTime = 150; int damage = 20; int ammo = 20; int clips = 20; winLevel: while (true) { int tick = 0; level++; int[] map = new int[1024 * 1024]; random = new Random(4329+level); int[] monsterData = new int[320 * 16]; { int i = 0; for (int y = 0; y < 1024; y++) for (int x = 0; x < 1024; x++) { int br = random.nextInt(32) + 112; map[i] = (br / 3) << 16 | (br) << 8; if (x < 4 || y < 4 || x >= 1020 || y >= 1020) { map[i] = 0xFFFEFE; } i++; } for (i = 0; i < 70; i++) { int w = random.nextInt(8) + 2; int h = random.nextInt(8) + 2; int xm = random.nextInt(64 - w - 2) + 1; int ym = random.nextInt(64 - h - 2) + 1; w *= 16; h *= 16; w += 5; h += 5; xm *= 16; ym *= 16; if (i==68) { monsterData[0] = xm+w/2; monsterData[1] = ym+h/2; monsterData[15] = 0x808080; monsterData[11] = 1; } xWin0 = xm+5; yWin0 = ym+5; xWin1 = xm + w-5; yWin1 = ym + h-5; for (int y = ym; y < ym + h; y++) for (int x = xm; x < xm + w; x++) { int d = x - xm; if (xm + w - x - 1 < d) d = xm + w - x - 1; if (y - ym < d) d = y - ym; if (ym + h - y - 1 < d) d = ym + h - y - 1; map[x + y * 1024] = 0xFF8052; if (d > 4) { int br = random.nextInt(16) + 112; if (((x + y) & 3) == 0) { br += 16; } map[x + y * 1024] = (br * 3 / 3) << 16 | (br * 4 / 4) << 8 | (br * 4 / 4); } if (i == 69) { map[x + y * 1024] &= 0xff0000; } } for (int j = 0; j < 2; j++) { int xGap = random.nextInt(w - 24) + xm + 5; int yGap = random.nextInt(h - 24) + ym + 5; int ww = 5; int hh = 5; xGap = xGap / 16 * 16 + 5; yGap = yGap / 16 * 16 + 5; if (random.nextInt(2) == 0) { xGap = xm + (w - 5) * random.nextInt(2); hh = 11; } else { ww = 11; yGap = ym + (h - 5) * random.nextInt(2); } for (int y = yGap; y < yGap + hh; y++) for (int x = xGap; x < xGap + ww; x++) { int br = random.nextInt(32) + 112 - 64; map[x + y * 1024] = (br * 3 / 3) << 16 | (br * 4 / 4) << 8 | (br * 4 / 4); } } } for (int y = 1; y < 1024 - 1; y++) inloop: for (int x = 1; x < 1024 - 1; x++) { for (int xx = x - 1; xx <= x + 1; xx++) for (int yy = y - 1; yy <= y + 1; yy++) if (map[xx + yy * 1024] < 0xff0000) continue inloop; map[x + y * 1024] = 0xffffff; } } long lastTime = System.nanoTime(); int[] lightmap = new int[240 * 240]; int[] brightness = new int[512]; double offs = 30; double playerDir = 0; for (int i = 0; i < 512; i++) { brightness[i] = (int) (255.0 * offs / (i + offs)); if (i < 4) brightness[i] = brightness[i] * i / 4; } Graphics sg = getGraphics(); random = new Random(); while (true) { if (gameStarted) { tick++; rushTime++; if (rushTime >= 150) { rushTime = -random.nextInt(2000); } // Move player: int mouse = m; playerDir = Math.atan2(mouse / 240 - 120, mouse % 240 - 120); double shootDir = playerDir + (random.nextInt(100) - random.nextInt(100)) / 100.0 * 0.2; double cos = Math.cos(-shootDir); double sin = Math.sin(-shootDir); int xCam = monsterData[0]; int yCam = monsterData[1]; for (int i = 0; i < 960; i++) { int xt = i % 240 - 120; int yt = (i / 240 % 2) * 239 - 120; if (i >= 480) { int tmp = xt; xt = yt; yt = tmp; } double dd = Math.atan2(yt, xt) - playerDir; if (dd < -Math.PI) dd += Math.PI * 2; if (dd >= Math.PI) dd -= Math.PI * 2; int brr = (int) ((1 - dd * dd) * 255); int dist = 120; if (brr < 0) { brr = 0; dist = 32; } if (tick < 60) brr = brr * tick / 60; int j = 0; for (; j < dist; j++) { int xx = xt * j / 120 + 120; int yy = yt * j / 120 + 120; int xm = xx + xCam - 120; int ym = yy + yCam - 120; if (map[(xm + ym * 1024) & (1024 * 1024 - 1)] == 0xffffff) break; int xd = (xx - 120) * 256 / 120; int yd = (yy - 120) * 256 / 120; int ddd = (xd * xd + yd * yd) / 256; int br = brightness[ddd] * brr / 255; if (ddd < 16) { int tmp = 128 * (16 - ddd) / 16; br = br + tmp * (255 - br) / 255; } lightmap[xx + yy * 240] = br; } } for (int y = 0; y < 240; y++) { int xm = xCam - 120; int ym = y + yCam - 120; for (int x = 0; x < 240; x++) { pixels[x + y * 240] = map[(xm + x + ym * 1024) & (1024 * 1024 - 1)]; } } int closestHitDist = 0; for (int j = 0; j < 250; j++) { int xm = xCam + (int) (cos * j / 2); int ym = yCam - (int) (sin * j / 2); if (map[(xm + ym * 1024) & (1024 * 1024 - 1)] == 0xffffff) break; closestHitDist = j / 2; } boolean shoot = shootDelay-- < 0 && k[1]; { int closestHit = 0; nextMonster: for (int m = 0; m < 256 + 16; m++) { int xPos = monsterData[m * 16 + 0]; int yPos = monsterData[m * 16 + 1]; if (monsterData[m * 16 + 11] == 0) { xPos = (random.nextInt(62) + 1) * 16 + 8; yPos = (random.nextInt(62) + 1) * 16 + 8; int xd = xCam - xPos; int yd = yCam - yPos; if (xd * xd + yd * yd < 180 * 180) { xPos = 1; yPos = 1; } if (map[xPos + yPos * 1024] < 0xfffffe && (m <= 128 || rushTime > 0 || (m > 255 && tick == 1))) { monsterData[m * 16 + 0] = xPos; monsterData[m * 16 + 1] = yPos; monsterData[m * 16 + 15] = map[xPos + yPos * 1024]; map[xPos + yPos * 1024] = 0xfffffe; monsterData[m * 16 + 9] = (rushTime > 0 || random.nextInt(3) == 0) ? 127 : 0; monsterData[m * 16 + 11] = 1; monsterData[m * 16 + 2] = m & 15; } else { continue; } } else { int xd = xPos - xCam; int yd = yPos - yCam; if (m >= 255) { if (xd * xd + yd * yd < 8 * 8) { map[xPos + yPos * 1024] = monsterData[m * 16 + 15]; monsterData[m * 16 + 11] = 0; bonusTime = 120; if ((m & 1) == 0) { damage = 20; } else { clips = 20; } continue; } } else if (xd * xd + yd * yd > 340 * 340) { map[xPos + yPos * 1024] = monsterData[m * 16 + 15]; monsterData[m * 16 + 11] = 0; continue; } } int xm = xPos - xCam + 120; int ym = monsterData[m * 16 + 1] - yCam + 120; int d = monsterData[m * 16 + 2]; if (m == 0) { d = (((int) (playerDir / (Math.PI * 2) * 16 + 4.5 + 16)) & 15); } d += ((monsterData[m * 16 + 3] / 4) & 3) * 16; int p = (0 * 16 + d) * 144; if (m > 0) { p += ((m & 15) + 1) * 144 * 16 * 4; } if (m > 255) { p = (17 * 4 * 16 + ((m & 1) * 16 + (tick & 15))) * 144; } for (int y = ym - 6; y < ym + 6; y++) for (int x = xm - 6; x < xm + 6; x++) { int c = sprites[p++]; if (c > 0 && x >= 0 && y >= 0 && x < 240 && y < 240) { pixels[x + y * 240] = c; } } boolean moved = false; if (monsterData[m * 16 + 10] > 0) { monsterData[m * 16 + 11] += random.nextInt(3) + 1; monsterData[m * 16 + 10] = 0; double rot = 0.25; int amount = 8; double poww = 32; if (monsterData[m * 16 + 11] >= 2+level) { rot = Math.PI * 2; amount = 60; poww = 16; map[(xPos) + (yPos) * 1024] = 0xa00000; monsterData[m * 16 + 11] = 0; score += level; } for (int i = 0; i < amount; i++) { double pow = (random.nextInt(100) * random.nextInt(100)) * poww / 10000+4; double dir = (random.nextInt(100) - random.nextInt(100)) / 100.0 * rot; double xdd = (Math.cos(playerDir + dir) * pow) + random.nextInt(4) - random.nextInt(4); double ydd = (Math.sin(playerDir + dir) * pow) + random.nextInt(4) - random.nextInt(4); int col = (random.nextInt(128) + 120); bloodLoop: for (int j = 2; j < pow; j++) { int xd = (int) (xPos + xdd * j / pow); int yd = (int) (yPos + ydd * j / pow); int pp = ((xd) + (yd) * 1024) & (1024 * 1024 - 1); if (map[pp] >= 0xff0000) break bloodLoop; if (random.nextInt(2) != 0) { map[pp] = col << 16; col = col * 8 / 9; } } } continue nextMonster; } int xPlayerDist = xCam - xPos; int yPlayerDist = yCam - yPos; if (m <= 255) { double rx = -(cos * xPlayerDist - sin * yPlayerDist); double ry = cos * yPlayerDist + sin * xPlayerDist; if (rx > -6 && rx < 6 && ry > -6 && ry < 6 && m > 0) { damage++; hurtTime += 20; } if (rx > -32 && rx < 220 && ry > -32 && ry < 32 && random.nextInt(10) == 0) { monsterData[m * 16 + 9]++; } if (rx > 0 && rx < closestHitDist && ry > -8 && ry < 8) { closestHitDist = (int) (rx); closestHit = m; } dirLoop: for (int i = 0; i < 2; i++) { int xa = 0; int ya = 0; xPos = monsterData[m * 16 + 0]; yPos = monsterData[m * 16 + 1]; if (m == 0) { if (k[KeyEvent.VK_A]) xa--; if (k[KeyEvent.VK_D]) xa++; if (k[KeyEvent.VK_W]) ya--; if (k[KeyEvent.VK_S]) ya++; } else { if (monsterData[m * 16 + 9] < 8) continue nextMonster; if (monsterData[m * 16 + 8] != 12) { xPlayerDist = (monsterData[m * 16 + 8]) % 5 - 2; yPlayerDist = (monsterData[m * 16 + 8]) / 5 - 2; if (random.nextInt(10) == 0) { monsterData[m * 16 + 8] = 12; } } double xxd = Math.sqrt(xPlayerDist * xPlayerDist); double yyd = Math.sqrt(yPlayerDist * yPlayerDist); if (random.nextInt(1024) / 1024.0 < yyd / xxd) { if (yPlayerDist < 0) ya--; if (yPlayerDist > 0) ya++; } if (random.nextInt(1024) / 1024.0 < xxd / yyd) { if (xPlayerDist < 0) xa--; if (xPlayerDist > 0) xa++; } moved = true; double dir = Math.atan2(yPlayerDist, xPlayerDist); monsterData[m * 16 + 2] = (((int) (dir / (Math.PI * 2) * 16 + 4.5 + 16)) & 15); } ya *= i; xa *= 1 - i; if (xa != 0 || ya != 0) { map[xPos + yPos * 1024] = monsterData[m * 16 + 15]; for (int xx = xPos + xa - 3; xx <= xPos + xa + 3; xx++) for (int yy = yPos + ya - 3; yy <= yPos + ya + 3; yy++) if (map[xx + yy * 1024] >= 0xfffffe) { map[xPos + yPos * 1024] = 0xfffffe; monsterData[m * 16 + 8] = random.nextInt(25); continue dirLoop; } moved = true; monsterData[m * 16 + 0] += xa; monsterData[m * 16 + 1] += ya; monsterData[m * 16 + 15] = map[(xPos + xa) + (yPos + ya) * 1024]; map[(xPos + xa) + (yPos + ya) * 1024] = 0xfffffe; } } if (moved) { monsterData[m * 16 + 3]++; } } } if (shoot) { if (ammo >= 220) { shootDelay = 2; k[1] = false; } else { shootDelay = 1; ammo += 4; } if (closestHit > 0) { monsterData[closestHit * 16 + 10] = 1; monsterData[closestHit * 16 + 9] = 127; } int glow = 0; for (int j = closestHitDist; j >= 0; j--) { int xm = +(int) (cos * j) + 120; int ym = -(int) (sin * j) + 120; if (xm > 0 && ym > 0 && xm < 240 && ym < 240) { if (random.nextInt(20) == 0 || j == closestHitDist) { pixels[xm + ym * 240] = 0xffffff; glow = 200; } lightmap[xm + ym * 240] += glow * (255 - lightmap[xm + ym * 240]) / 255; } glow = glow * 20 / 21; } if (closestHitDist < 120) { closestHitDist -= 3; int xx = (int) (120 + cos * closestHitDist); int yy = (int) (120 - sin * closestHitDist); for (int x = -12; x <= 12; x++) { for (int y = -12; y <= 12; y++) { int xd = xx + x; int yd = yy + y; if (xd >= 0 && yd >= 0 && xd < 240 && yd < 240) { lightmap[xd + yd * 240] += 2000 / (x * x + y * y + 10) * (255 - lightmap[xd + yd * 240]) / 255; } } } for (int i = 0; i < 10; i++) { double pow = random.nextInt(100) * random.nextInt(100) * 8.0 / 10000; double dir = (random.nextInt(100) - random.nextInt(100)) / 100.0; int xd = (int) (xx - Math.cos(playerDir + dir) * pow) + random.nextInt(4) - random.nextInt(4); int yd = (int) (yy - Math.sin(playerDir + dir) * pow) + random.nextInt(4) - random.nextInt(4); if (xd >= 0 && yd >= 0 && xd < 240 && yd < 240) { if (closestHit > 0) { pixels[xd + yd * 240] = 0xff0000; } else { pixels[xd + yd * 240] = 0xcacaca; } } } } } } if (damage >= 220) { k[1] = false; hurtTime = 255; continue restart; } if (k[KeyEvent.VK_R] && ammo > 20 && clips < 220) { shootDelay = 30; ammo = 20; clips += 10; } if (xCam > xWin0 && xCam < xWin1 && yCam > yWin0 && yCam < yWin1) { continue winLevel; } } bonusTime = bonusTime * 8 / 9; hurtTime /= 2; for (int y = 0; y < 240; y++) { for (int x = 0; x < 240; x++) { int noise = random.nextInt(16) * random.nextInt(16) / 16; if (!gameStarted) noise *= 4; int c = pixels[x + y * 240]; int l = lightmap[x + y * 240]; lightmap[x + y * 240] = 0; int r = ((c >> 16) & 0xff) * l / 255 + noise; int g = ((c >> 8) & 0xff) * l / 255 + noise; int b = ((c) & 0xff) * l / 255 + noise; r = r * (255 - hurtTime) / 255 + hurtTime; g = g * (255 - bonusTime) / 255 + bonusTime; pixels[x + y * 240] = r << 16 | g << 8 | b; } if (y % 2 == 0 && (y >= damage && y < 220)) { for (int x = 232; x < 238; x++) { pixels[y * 240 + x] = 0x800000; } } if (y % 2 == 0 && (y >= ammo && y < 220)) { for (int x = 224; x < 230; x++) { pixels[y * 240 + x] = 0x808000; } } if (y % 10 < 9 && (y >= clips && y < 220)) { for (int x = 221; x < 222; x++) { pixels[y * 240 + 221] = 0xffff00; } } } ogr.drawString("" + score, 4, 232); if (!gameStarted) { ogr.drawString("Left 4k Dead", 80, 70); if (k[1] && hurtTime == 0) { score = 0; gameStarted = true; k[1] = false; } } else if (tick < 60) { ogr.drawString("Level " + level, 90, 70); } sg.drawImage(image, 0, 0, 480, 480, 0, 0, 240, 240, null); do { Thread.yield(); } while (System.nanoTime() - lastTime < 0); if (!isActive()) return; lastTime += (1000000000 / 30); } } } } public void processEvent(AWTEvent e) { boolean down = false; switch (e.getID()) { case KeyEvent.KEY_PRESSED: down = true; case KeyEvent.KEY_RELEASED: k[((KeyEvent) e).getKeyCode()] = down; break; case MouseEvent.MOUSE_PRESSED: down = true; case MouseEvent.MOUSE_RELEASED: k[((MouseEvent) e).getButton()] = down; case MouseEvent.MOUSE_MOVED: case MouseEvent.MOUSE_DRAGGED: m = ((MouseEvent) e).getX() / 2 + ((MouseEvent) e).getY() / 2 * 240; } } }
codingcampbell/Left-4k-Dead
G.java
684
import java.io.*; class A { public void A(int n) { for(int x=1;x<=n;x++) { for(int y=1;y<=n;y++) { if(x==1||y==1||y==n||x==(n/2)) System.out.print("#"); else System.out.print(" "); } System.out.println(); } }
sachin-cpp/MyPatterns
A.java
685
class A implements Runnable { public void run() { for(int i=1;i<=4;i++) { try { Thread.sleep(800); System.out.println(i+" "+Thread.currentThread().getName()); } catch(Exception e) { System.out.println(e); } //System.out.println(i+" "+Thread.currentThread().getName()); //System.out.println(i+" "+Thread.currentThread().getPriority()); } } public static void main(String arg[]) { A ob = new A(); Thread t = new Thread(ob); Thread t1 = new Thread(ob); Thread t2 = new Thread(ob); t1.setPriority(Thread.MAX_PRIORITY); t.setPriority(Thread.MIN_PRIORITY); t2.setPriority(Thread.NORM_PRIORITY); t.start(); try { t.join(); } catch(Exception e) { System.out.println(e); } t1.start(); t2.start(); } }
niteshctz25/Java
A.java
686
class Solution { public: string convert(string s, int numRows) { if(numRows <= 1) return s; vector<string>v(numRows, ""); int j = 0, dir = -1; for(int i = 0; i < s.length(); i++) { if(j == numRows - 1 || j == 0) dir *= (-1); v[j] += s[i]; if(dir == 1) j++; else j--; } string res; for(auto &it : v) res += it; return res; } };
subhagittu/Leetcode
6.java
687
class Solution { public int integerBreak(int n) { int[] dp = new int[n + 1]; dp[1] = 1; for (int i = 2; i <= n; i++) { for (int j = 1; j < i; j++) { dp[i] = Math.max(dp[i], Math.max(j, dp[j]) * (i - j)); } } return dp[n]; } public static void main(String[] args) { Solution solution = new Solution(); int n1 = 2; System.out.println(solution.integerBreak(n1)); int n2 = 10; System.out.println(solution.integerBreak(n2)); } }
dhruvabhat24/Leetcode_October
8.java
688
class Solution { public boolean winnerOfGame(String colors) { int aliceCount = 0; int bobCount = 0; for (int i = 1; i < colors.length() - 1; i++) { if (colors.charAt(i - 1) == 'A' && colors.charAt(i) == 'A' && colors.charAt(i + 1) == 'A') { aliceCount++; } else if (colors.charAt(i - 1) == 'B' && colors.charAt(i) == 'B' && colors.charAt(i + 1) == 'B') { bobCount++; } } return aliceCount > bobCount; } }
dhruvabhat24/Leetcode_October
4.java
691
class x { public static void main(String[] args) { long sum = 0; for (int i = 1; i <= 100000000; ++i) sum += i; System.out.println(sum); } }
zerosign/x
x.java
692
class Solution { public List<Integer> majorityElement(int[] nums) { int candidate1 = 0, candidate2 = 0, count1 = 0, count2 = 0; for (int num : nums) { if (num == candidate1) { count1++; } else if (num == candidate2) { count2++; } else if (count1 == 0) { candidate1 = num; count1 = 1; } else if (count2 == 0) { candidate2 = num; count2 = 1; } else { count1--; count2--; } } count1 = 0; count2 = 0; for (int num : nums) { if (num == candidate1) { count1++; } else if (num == candidate2) { count2++; } } List<Integer> result = new ArrayList<>(); if (count1 > nums.length / 3) { result.add(candidate1); } if (count2 > nums.length / 3) { result.add(candidate2); } return result; } public static void main(String[] args) { Solution solution = new Solution(); int[] nums = {3, 3, 3, 2, 2, 1, 1, 1}; List<Integer> result = solution.majorityElement(nums); System.out.println(result); } }
dhruvabhat24/Leetcode_October
7.java
693
class Solution { public boolean isMonotonic(int[] nums) { boolean increasing = true; boolean decreasing = true; for (int i = 1; i < nums.length; i++) { if (nums[i] < nums[i - 1]) { increasing = false; break; } } for (int i = 1; i < nums.length; i++) { if (nums[i] > nums[i - 1]) { decreasing = false; break; } } return increasing || decreasing; } }
dhruvabhat24/Leetcode_October
1.java
694
import java.awt.Canvas; import java.awt.Color; import java.awt.Graphics; import java.io.IOException; import javax.swing.JFrame; import javax.swing.WindowConstants; public class B extends Canvas { private static final int SCALE = 10; public static void drawPicture(double[] values) { try { int dim = (int) Math.sqrt(values.length); double[][] newValues = new double[dim][dim]; for (int i = 0; i < values.length; i++) { newValues[i % dim][i / dim] = values[i]; } drawPicture(dim, newValues); } catch (Exception e) { return; } } public static void drawPicture(int dim, double[][] newValues) { JFrame frame = new JFrame(); frame.setSize(50 + Math.max(280, SCALE*dim), 50 + Math.max(280, SCALE*dim)); frame.add(new B(newValues)); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.setVisible(true); } private static final long serialVersionUID = 1480902466428347458L; private final int WIDTH; private final int HEIGHT; private double[][] values; public B(double[][] values) { super(); this.WIDTH = values.length; this.HEIGHT = values[0].length; this.values = values; } @Override public void paint(Graphics g) { super.paint(g); for (int x = 0; x < WIDTH; x++) { for (int y = 0; y < HEIGHT; y++) { g.setColor(color(this.values[x][y])); for (int i = 0; i < SCALE; i++) { for (int j = 0; j < SCALE; j++) { g.drawLine(SCALE*x + i, SCALE*y + j, SCALE*x + i, SCALE*y + j); } } } } } private Color color(double value) { return Color.getHSBColor(fromValue(value), 1.0f, .5f); } private float fromValue(double value) { return (float) (((300 * (1.0 - value) + 300) % 360) / 360.0); } }
CMU-17-214/f22-rec12
B.java
695
package gitlet; import java.io.File; import java.io.IOException; import java.io.Serializable; import java.io.UnsupportedEncodingException; import java.nio.charset.StandardCharsets; import java.security.NoSuchAlgorithmException; import java.util.Date; import java.text.SimpleDateFormat; import java.util.Map; import java.util.TreeMap; public class Commit implements Serializable { /**this is.*/ static final File REPO_FOLDER = new File(".", ".gitlet"); /**this is.*/ static final File COMMIT_FOLDER = new File(REPO_FOLDER, "Commits"); public Commit() { _Message = "initial commit"; _Date = new Date(0, 0, 0, 0, 0, 0); _Parent = null; _ParentSecond = null; String hashMessage = _Message + _Date.toString(); _Hash = toSHA1(hashMessage.getBytes(StandardCharsets.UTF_8)); _Map = new TreeMap<>(); _Map.put(_Hash, 0); } public Commit(File parent, Date d, String message) throws NoSuchAlgorithmException, UnsupportedEncodingException { _Date = d; _Parent = parent; _ParentSecond = null; _Message = message; String hashMessage = _Message + _Date.toString(); if (_Parent != null) { hashMessage += _Parent.getName(); } _Hash = toSHA1(hashMessage.getBytes(StandardCharsets.UTF_8)); _Map = new TreeMap<>(); TreeMap<String, Integer> oldMap = new TreeMap<>(Commit.readCommit(parent.getName()).getMap()); for (Map.Entry<String, Integer> entry : oldMap.entrySet()) { _Map.put(entry.getKey(), entry.getValue() + 1); } _Map.put(_Hash, 0); } public Commit(File parent, File parent2, Date d, String message) throws NoSuchAlgorithmException, UnsupportedEncodingException { _Date = d; _Parent = parent; _ParentSecond = parent2; _Message = message; String hashMessage = _Message + _Date.toString(); if (_Parent != null) { hashMessage += _Parent.getName(); } _Hash = toSHA1(hashMessage.getBytes(StandardCharsets.UTF_8)); _Map = new TreeMap<>(); TreeMap<String, Integer> oldMap = new TreeMap<>(Commit.readCommit(parent.getName()).getMap()); for (Map.Entry<String, Integer> entry : oldMap.entrySet()) { _Map.put(entry.getKey(), entry.getValue() + 1); } TreeMap<String, Integer> secondOldMap = new TreeMap<>(Commit.readCommit(parent2.getName()).getMap()); for (Map.Entry<String, Integer> entry : secondOldMap.entrySet()) { _Map.put(entry.getKey(), entry.getValue() + 1); } _Map.put(_Hash, 0); } public void makeFolderWithMessage(String s) { File thisCommit = new File(COMMIT_FOLDER, s); if (!thisCommit.exists()) { thisCommit.mkdir(); } else { throw new RuntimeException( "why are we trying to make" + " this commit into a folder twice: " + s); } } public void writeCommit() throws IOException { File tHISCOMMIT = new File(COMMIT_FOLDER, getHash()); File thisCommit = new File(tHISCOMMIT, "thisCommitObject"); if (!thisCommit.exists()) { thisCommit.createNewFile(); } Utils.writeObject(thisCommit, this); } public static Commit readCommit(String name) { File file = new File(COMMIT_FOLDER, name); File f = new File(file, "thisCommitObject"); if (!f.exists()) { throw new GitletException("This commit doesnt' exist " + name); } Commit b = Utils.readObject(f, Commit.class); return b; } public static String toSHA1(byte[] convertme) { return Utils.sha1(convertme); } public String getTimeFormatted() { Date d = getDate(); SimpleDateFormat sdf = new SimpleDateFormat( "EEE MMM dd HH:mm:ss yyyy Z"); return sdf.format(d); } public Date getDate() { return _Date; } public String getHash() { return _Hash; } public String getMessage() { return _Message; } public File getParent() { return _Parent; } public File getSecondParent() { return _ParentSecond; } public TreeMap<String, Integer> getMap() { return _Map; } /**this is.*/ private TreeMap<String, Integer> _Map; /**this is.*/ private File _Parent; /**this is.*/ private File _ParentSecond; /**this is.*/ private Date _Date; /**this is.*/ private String _Hash; /**this is.*/ private String _Message; }
cparmstrong03/gitlet-repo
commit
696
public class SecondLargestInArrayExample{ public static int getSecondLargest(int[] a, int total){ int temp; for (int i = 0; i < total; i++) { for (int j = i + 1; j < total; j++) { if (a[i] > a[j]) { temp = a[i]; a[i] = a[j]; a[j] = temp; } } } return a[total-2]; } public static void main(String args[]){ int a[]={1,2,5,6,3,2}; int b[]={44,66,99,77,33,22,55}; System.out.println("Second Largest: "+getSecondLargest(a,6)); System.out.println("Second Largest: "+getSecondLargest(b,7)); }}
pratiksh404/nepactober
fintsecondlargestnumberinarray.java
698
import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Arrays; import java.util.Random; public class SortingApp extends JFrame { private JComboBox<String> dataTypeComboBox; private JTextArea resultTextArea; private JButton sortButton; public SortingApp() { setTitle("Sorting Application"); setSize(400, 300); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); dataTypeComboBox = new JComboBox<>(new String[]{"Integer", "Double", "String"}); panel.add(dataTypeComboBox, BorderLayout.NORTH); resultTextArea = new JTextArea(); resultTextArea.setEditable(false); JScrollPane scrollPane = new JScrollPane(resultTextArea); panel.add(scrollPane, BorderLayout.CENTER); sortButton = new JButton("Sort Data"); panel.add(sortButton, BorderLayout.SOUTH); sortButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { sortData(); } }); add(panel); } private void sortData() { String dataType = (String) dataTypeComboBox.getSelectedItem(); long startTime = System.currentTimeMillis(); if ("Integer".equals(dataType)) { sortIntegerData(); resultTextArea.append("Integer Type -- "); } else if ("Double".equals(dataType)) { sortDoubleData(); resultTextArea.append("Double Type -- "); } else if ("String".equals(dataType)) { sortStringData(); resultTextArea.append("String Type -- "); } long endTime = System.currentTimeMillis(); long elapsedTime = endTime - startTime; resultTextArea.append("Data sorted in " + elapsedTime + " milliseconds.\n"); } private void sortIntegerData() { int[] data = generateRandomIntegers(100000); Arrays.sort(data); } private void sortDoubleData() { double[] data = generateRandomDoubles(100000); Arrays.sort(data); } private void sortStringData() { String[] data = generateRandomStrings(100000); Arrays.sort(data); } private int[] generateRandomIntegers(int size) { int[] data = new int[size]; Random random = new Random(); for (int i = 0; i < size; i++) { data[i] = random.nextInt(); } return data; } private double[] generateRandomDoubles(int size) { double[] data = new double[size]; Random random = new Random(); for (int i = 0; i < size; i++) { data[i] = random.nextDouble(); } return data; } private String[] generateRandomStrings(int size) { String[] data = new String[size]; Random random = new Random(); for (int i = 0; i < size; i++) { data[i] = Long.toHexString(Double.doubleToLongBits(random.nextDouble())); } return data; } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { new SortingApp().setVisible(true); } }); } }
r-vb/java
9.java
700
package cofh.thermalfoundation.world.biome; import net.minecraft.world.biome.Biome; import net.minecraft.world.biome.Biome.BiomeProperties; import net.minecraftforge.common.BiomeDictionary; import net.minecraftforge.common.BiomeManager; import net.minecraftforge.common.BiomeManager.BiomeType; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.registries.IForgeRegistry; import java.util.ArrayList; import static net.minecraftforge.common.BiomeDictionary.Type.*; public class TFBiomes { public static final TFBiomes INSTANCE = new TFBiomes(); private TFBiomes() { } /* INIT */ public static void preInit() { biomeFluxed = new BiomeFluxed(new BiomeProperties("Fluxed").setTemperature(0.8F).setRainfall(0.7F).setBaseHeight(0.1F).setHeightVariation(0.0F)); MinecraftForge.EVENT_BUS.register(INSTANCE); } public static void postInit() { for (WrappedBiomeEntry wrapped : biomeList) { wrapped.initialize(); } } /* EVENT HANDLING */ @SubscribeEvent public void registerBiomes(RegistryEvent.Register<Biome> event) { IForgeRegistry<Biome> registry = event.getRegistry(); register(registry, biomeFluxed, "meadow", BiomeType.COOL, 7000000, true, true, true, PLAINS, LUSH, WET); } public static void register(IForgeRegistry<Biome> registry, Biome biome, String name, BiomeType type, int weight, boolean enable, boolean spawn, boolean village, BiomeDictionary.Type... biomeDictTypes) { if (!enable) { return; } biome.setRegistryName(name); registry.register(biome); for (BiomeDictionary.Type biomeDictType : biomeDictTypes) { BiomeDictionary.addTypes(biome, biomeDictType); } biomeList.add(new WrappedBiomeEntry(biome, type, weight, spawn, village)); } private static ArrayList<WrappedBiomeEntry> biomeList = new ArrayList<>(); /* REFERENCES */ public static BiomeFluxed biomeFluxed; /* BIOME DATA CLASS */ public static class WrappedBiomeEntry { public final Biome biome; public final BiomeType type; public final boolean spawn; public final boolean village; public final BiomeManager.BiomeEntry entry; public WrappedBiomeEntry(Biome biome, BiomeType type, int weight, boolean spawn, boolean village) { this.biome = biome; this.type = type; this.spawn = spawn; this.village = village; this.entry = new BiomeManager.BiomeEntry(biome, weight); } public void initialize() { BiomeManager.addBiome(type, entry); if (village) { BiomeManager.addVillageBiome(biome, true); } if (spawn) { BiomeManager.addSpawnBiome(biome); } } } }
Mario-Kart-Felix/Rh-Null-blood-type
Biome
702
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.UncheckedIOException; import java.io.Closeable; import java.io.Writer; import java.io.OutputStreamWriter; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author daltao */ public class Main { public static void main(String[] args) throws Exception { Thread thread = new Thread(null, new TaskAdapter(), "daltao", 1 << 27); thread.start(); thread.join(); } static class TaskAdapter implements Runnable { @Override public void run() { InputStream inputStream = System.in; OutputStream outputStream = System.out; FastInput in = new FastInput(inputStream); FastOutput out = new FastOutput(outputStream); TaskE solver = new TaskE(); solver.solve(1, in, out); out.close(); } } static class TaskE { public void solve(int testNumber, FastInput in, FastOutput out) { int n = in.readInt(); long total = 0; for (int i = 1; i <= 9; i += 1) { total += count(new int[i], n, 0, i * 2); total += count(new int[i + 1], n, 0, i * 2 + 1); } out.println(total); } public long count(int[] diff, long sum, int i, int digitNum) { if (i == diff.length) { if (sum != 0) { return 0; } long ways = 1; for (int j = 0; j < diff.length; j++) { long localWay = 0; for (int k = j == 0 ? 1 : 0; k < 10; k++) { int t = k + diff[j]; if (t < 0 || t >= 10) { continue; } localWay++; } ways *= localWay; } return ways; } int v; if (sum >= 0) { v = 10 - DigitUtils.digitOn(sum, i); } else { v = DigitUtils.digitOn(sum, i); } long ans = 0; diff[i] = v; ans += count(diff, sum + DigitUtils.setDigitOn(0, i, diff[i]) - DigitUtils.setDigitOn(0, digitNum - 1 - i, diff[i]), i + 1, digitNum); diff[i] = v - 10; ans += count(diff, sum + DigitUtils.setDigitOn(0, i, diff[i]) - DigitUtils.setDigitOn(0, digitNum - 1 - i, diff[i]), i + 1, digitNum); return ans; } } static class FastOutput implements AutoCloseable, Closeable { private StringBuilder cache = new StringBuilder(10 << 20); private final Writer os; public FastOutput(Writer os) { this.os = os; } public FastOutput(OutputStream os) { this(new OutputStreamWriter(os)); } public FastOutput println(long c) { cache.append(c).append('\n'); return this; } public FastOutput flush() { try { os.append(cache); cache.setLength(0); } catch (IOException e) { throw new UncheckedIOException(e); } return this; } public void close() { flush(); try { os.close(); } catch (IOException e) { throw new UncheckedIOException(e); } } } static class FastInput { private final InputStream is; private byte[] buf = new byte[1 << 13]; private int bufLen; private int bufOffset; private int next; public FastInput(InputStream is) { this.is = is; } private int read() { while (bufLen == bufOffset) { bufOffset = 0; try { bufLen = is.read(buf); } catch (IOException e) { throw new RuntimeException(e); } if (bufLen == -1) { return -1; } } return buf[bufOffset++]; } public void skipBlank() { while (next >= 0 && next <= 32) { next = read(); } } public int readInt() { int sign = 1; skipBlank(); if (next == '+' || next == '-') { sign = next == '+' ? 1 : -1; next = read(); } int val = 0; if (sign == 1) { while (next >= '0' && next <= '9') { val = val * 10 + next - '0'; next = read(); } } else { while (next >= '0' && next <= '9') { val = val * 10 - next + '0'; next = read(); } } return val; } } static class DigitUtils { private static final long[] DIGIT_VALUES = new long[19]; static { DIGIT_VALUES[0] = 1; for (int i = 1; i < 19; i++) { DIGIT_VALUES[i] = DIGIT_VALUES[i - 1] * 10; } } private DigitUtils() { } public static int digitOn(long x, int i) { if (x < 0) { return digitOn(-x, i); } x /= DIGIT_VALUES[i]; return (int) (x % 10); } public static long setDigitOn(long x, int i, int newDigit) { if (x < 0) { return -setDigitOn(-x, i, newDigit); } return x + (newDigit - digitOn(x, i)) * DIGIT_VALUES[i]; } } }
Intelligent-CAT-Lab/CodeMind
dataset/CodeNet/CodeNet-Java/p03704_s598998779/Main.java
705
package lab; import java.util.*; public class T { public int k = 0; static class Move { int i, j; }; public void grid(char grid[][], int input, int flag) { if (flag == 9) { System.out.println("\nDraw\n"); } else { char inp; if (flag % 2 == 0) { inp = 'x'; } else { inp = 'o'; } switch (input) { case 1: if (grid[0][0] != '\0') { System.out.println("already exist in that place enter valid input"); k--; break; } else { grid[0][0] = inp; break; } case 2: if (grid[0][1] != '\0') { System.out.println("already exist in that place enter valid input"); k--; break; } else { grid[0][1] = inp; break; } case 3: if (grid[0][2] != '\0') { System.out.println("already exist in that place enter valid input"); k--; break; } else { grid[0][2] = inp; break; } case 4: if (grid[1][0] != '\0') { System.out.println("already exist in that place enter valid input"); k--; break; } else { grid[1][0] = inp; break; } case 5: if (grid[1][1] != '\0') { System.out.println("already exist in that place enter valid input"); k--; break; } else { grid[1][1] = inp; break; } case 6: if (grid[1][2] != '\0') { System.out.println("already exist in that place enter valid input"); k--; break; } else { grid[1][2] = inp; break; } case 7: if (grid[2][0] != '\0') { System.out.println("already exist in that place enter valid input"); k--; break; } else { grid[2][0] = inp; break; } case 8: if (grid[2][1] != '\0') { System.out.println("already exist in that place enter valid input"); k--; break; } else { grid[2][1] = inp; break; } case 9: if (grid[2][2] != '\0') { System.out.println("already exist in that place enter valid input"); k--; break; } else { grid[2][2] = inp; break; } default: System.out.println("invalid input"); } } } static char player = 'x', opponent = 'o'; static Boolean isMovesLeft(char board[][]) { for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) if (board[i][j] == '\0') return true; return false; } static int eval(char[][] grid) { // for checking row for (int i = 0; i < 3; i++) { if (grid[i][0] == grid[i][1] && grid[i][1] == grid[i][2]) { if (grid[i][0] == player) { return +10; } else if (grid[i][0] == opponent) { return -10; } } } // for checking columns for (int i = 0; i < 3; i++) { if (grid[0][i] == grid[1][i] && grid[1][i] == grid[2][i]) { if (grid[0][i] == player) { return +10; } else if (grid[0][i] == opponent) { return -10; } } } // for checking diagonals if (grid[0][0] == grid[1][1] && grid[1][1] == grid[2][2]) { if (grid[0][0] == player) { return 10; } else if (grid[0][0] == opponent) { return -10; } } if (grid[0][2] == grid[1][1] && grid[1][1] == grid[2][0]) { if (grid[0][2] == player) { return 10; } else if (grid[0][2] == opponent) { return -10; } } return 0; } static int minimax(int depth, char[][] grid, boolean isMax,int alpha,int beta) { int value = eval(grid); if (value == 10) { return 10; } if (value == -10) { return -10; } if (isMovesLeft(grid) == false) return 0; if (isMax) { int best = -1000; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { // Check if cell is empty if (grid[i][j] == '\0') { // Make the move grid[i][j] = player; best = Math.max(minimax(depth + 1, grid, !isMax,alpha,beta), best); best = Math.max(best, value); alpha = Math.max(alpha, best); grid[i][j] = '\0'; } } } return best; } else { int best = 1000; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { // Check if cell is empty if (grid[i][j] == '\0') { // Make the move grid[i][j] = 'o'; best = Math.min(minimax(depth + 1, grid, !isMax,alpha,beta), best); grid[i][j] = '\0'; } } } return best; } } void display(char[][] grid) { System.out.println("here's your input"); System.out.print(" " + grid[0][0] + " |"); System.out.print(" " + grid[0][1] + " | " + grid[0][2]); System.out.print("\n-- "); System.out.print("-- "); System.out.print("-- "); System.out.print("-- "); System.out.print("\n " + grid[1][0] + " |"); System.out.print(" " + grid[1][1] + " | " + grid[1][2]); System.out.print("\n-- "); System.out.print("-- "); System.out.print("-- "); System.out.print("-- "); System.out.print("\n " + grid[2][0] + " |"); System.out.print(" " + grid[2][1] + " | " + grid[2][2]); } static Move AIMove(char[][] grid) { int best = -1000; Move ob = new Move(); ob.i = -1; ob.j = -1; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { // Check if cell is empty if (grid[i][j] == '\0') { // Make the move grid[i][j] = player; int value = minimax(0, grid, false,10,-10); grid[i][j] = '\0'; if (value > best) { ob.i = i; ob.j = j; best = value; } } } } return ob; } public static void main(String[] args) { T ob1 = new T(); Scanner sc = new Scanner(System.in); char[][] grid = new char[3][3]; boolean finished = false; for (ob1.k = 0; ob1.k < 10 && !finished; ob1.k++) { int input = 0; if (ob1.k < 9 && ob1.k % 2 == 0) { System.out.println("\nai move"); Move ob = AIMove(grid); input = ob.i * 3 + ob.j +1; } else if (ob1.k < 9 && ob1.k % 2 != 0) { System.out.println("\nenter the square the player wants to put sign x"); input = sc.nextInt(); } ob1.grid(grid, input, ob1.k); ob1.display(grid); for (int i = 0; i < 3; i++) { if (grid[i][0] == grid[i][1] && grid[i][1] == grid[i][2]) { if (grid[i][0] == 'x' && grid[i][0] != '\0') { System.out.println("player x is winner"); finished = true; break; } else if (grid[i][0] == 'o' && grid[i][0] != '\0') { System.out.println("player 0 is winner"); finished = true; break; } } } // checking if any winner appeared on columns for (int i = 0; i < 3; i++) { if (grid[0][i] == grid[1][i] && grid[1][i] == grid[2][i]) { if (grid[0][i] == 'x' && grid[0][i] != '\0') { System.out.println("player x is winner"); finished = true; break; } else if (grid[0][i] == 'o' && grid[0][i] != '\0') { System.out.println("player 0 is winner"); finished = true; break; } } } // checking if any winner appeared on diagonals if (grid[0][0] == grid[1][1] && grid[1][1] == grid[2][2]) { if (grid[0][0] == 'x' && grid[0][0] != '\0') { System.out.println("player x is winner3"); finished = true; break; } else if (grid[0][0] == 'o' && grid[0][0] != '\0') { System.out.println("player 0 is winner"); finished = true; break; } } if (grid[0][2] == grid[1][1] && grid[1][1] == grid[2][0]) { if (grid[0][2] == 'x' && grid[0][2] != '\0') { System.out.println("player x is winner4"); break; } else if (grid[0][2] == 'o' && grid[0][2] != '\0') { System.out.println("player 0 is winner"); break; } } } } }
Spacecode10/UnbeatableTikTakToe
T.java
707
 import android.util.Log; //Logcat统一管理类 public class L { private L() { /* cannot be instantiated */ throw new UnsupportedOperationException("cannot be instantiated"); } public static boolean isDebug = true;// 是否需要打印bug,可以在application的onCreate函数里面初始化 private static final String TAG = "way"; // 下面四个是默认tag的函数 public static void i(String msg) { if (isDebug) Log.i(TAG, msg); } public static void d(String msg) { if (isDebug) Log.d(TAG, msg); } public static void e(String msg) { if (isDebug) Log.e(TAG, msg); } public static void v(String msg) { if (isDebug) Log.v(TAG, msg); } // 下面是传入自定义tag的函数 public static void i(String tag, String msg) { if (isDebug) Log.i(tag, msg); } public static void d(String tag, String msg) { if (isDebug) Log.i(tag, msg); } public static void e(String tag, String msg) { if (isDebug) Log.i(tag, msg); } public static void v(String tag, String msg) { if (isDebug) Log.i(tag, msg); } }
hoaye/AndroidTools
Tools/L.java
717
abstract class Display{ abstract void massage(); void printmassage(){ System.out.println("Hello java"); } } class Message extends Display{ void massage(){ System.out.println("Java is a good language"); } } class Deside extends Display{ void massage(){ System.out.println("Java is a programming language"); } } class Challenge extends Message{ void massage(){ System.out.println("this is sub class"); } void massagep(){ System.out.println("Java is a oop language"); } } public class AbstractMet { public static void main(String s[]){ Challenge c=new Challenge(); c.massage(); c.massagep(); c.printmassage(); } }
Vikash975814/complete-java-
A.java
718
import java.util.*; public class C { public static void main (String[] args) { //Board //Input Scanner input = new Scanner(System.in); //Get number of test cases int n = input.nextInt(); input.nextLine(); //Loop for (int i = 0; i < n; i++) { String dim = input.nextLine(); int height = Integer.parseInt(dim.split("x")[0]); int width = Integer.parseInt(dim.split("x")[1]); Character[][] board = new Character[height][width]; for (int h = 0; h < height; h++) { String line = input.nextLine(); for (int w = 0; w < width; w++) { board[h][w] = line.charAt(w); } } /*for (int h = 0; h < height; h++) { for (int w = 0; w < width; w++) { System.out.print(board[h][w]); } System.out.println(); }*/ int CASES=input.nextInt(); for (int k=0;k<CASES;k++ ){ int ax,ay,bx,by; ay=input.nextInt()-1; ax=input.nextInt()-1; by=input.nextInt()-1; bx=input.nextInt()-1; //got the test cases if ( board[ay][ax]=='E' || board[by][bx]!='E') { //no way System.out.println(0); } else { int result=move(board,ax,ay,bx,by); System.out.println(result); //switch positions } } if (input.hasNextLine()) { input.nextLine(); //reset buffer } } } static void dist_surround(Character[][] board, int sx, int sy, int ex, int ey,boolean okmap[][], ArrayList<Integer> distances, ArrayList<Integer> posxlist, ArrayList<Integer>posylist, ArrayList<Integer> movelist, int currentnummoves ) { int distanceN = Integer.MAX_VALUE; int distanceS = Integer.MAX_VALUE; int distanceE = Integer.MAX_VALUE; int distanceW = Integer.MAX_VALUE; int arrlen=0; //if (sx == ex && sy == ey) // return 0; if (safe(board, sx, sy-1,okmap) ){//|| (sx==ex && sy-1==ey)) { //NORTH //System.out.println("NORTH"); distanceN = distance(sx, sy-1, ex, ey); // distanceN = distance(sx, ex, sy-1, ey); okmap[sy-1][sx]=false; posxlist.add(sx); posylist.add(sy-1); movelist.add(currentnummoves+1); arrlen++; } if (safe(board, sx, sy+1,okmap)){//|| (sx==ex && sy+1==ey)) { //SOUTH //System.out.println("SOUTH"); distanceS = distance(sx, sy+1, ex, ey); posxlist.add(sx); posylist.add(sy+1); movelist.add(currentnummoves+1); okmap[sy+1][sx]=false; arrlen++; } if (safe(board, sx+1, sy,okmap)){//|| (sx+1==ex && sy==ey)) { //EAST //System.out.println("EAST"); distanceE = distance(sx+1, sy, ex, ey); posxlist.add(sx+1); posylist.add(sy); movelist.add(currentnummoves+1); okmap[sy][sx+1]=false; arrlen++; } if (safe(board, sx-1, sy,okmap)){//|| (sx-1==ex && sy==ey)) { //System.out.println("WEST"); distanceW = distance(sx-1, sy, ex, ey); posxlist.add(sx-1); posylist.add(sy); movelist.add(currentnummoves+1); okmap[sy][sx-1]=false; arrlen++; } if (distanceN!=Integer.MAX_VALUE) distances.add(distanceN); if (distanceS!=Integer.MAX_VALUE) distances.add(distanceS); if (distanceE!=Integer.MAX_VALUE) distances.add(distanceE); if (distanceW!=Integer.MAX_VALUE) distances.add(distanceW); //construct the array } private static int nextPosition(ArrayList<Integer> distancelist) { //returns position of next closest distance //-1 indicates no more entries, -2 or more indicates we have found the expected int min=Integer.MAX_VALUE; int leastindex=-1; for (int i=0;i<distancelist.size();i++) { if (distancelist.get(i)<0) continue; if (distancelist.get(i)<min) { min=distancelist.get(i); leastindex=i; } } //if min is 0, return the negative number corresponding to its position (so we can return # of moves) if (min==0 ) { leastindex=-1*(leastindex+2); } return leastindex; } private static int move(Character[][] board, int sx, int sy, int ex, int ey) { boolean okmap[][]=new boolean [board.length][board[0].length]; for (int i=0;i<board.length;i++) { for (int j=0;j<board[0].length;j++) { okmap[i][j]=true; } } //System.out.println(okmap[0][0]); okmap[sy][sx]=false; ArrayList<Integer> movelist=new ArrayList<Integer>(); ArrayList<Integer> distancelist=new ArrayList<Integer>(); ArrayList<Integer> posxlist=new ArrayList<Integer>(); ArrayList<Integer> posylist=new ArrayList<Integer>(); posxlist.add(sx); posylist.add(sy); movelist.add(0); distancelist.add(distance(sx,sy,ex,ey)); int nexpos=nextPosition(distancelist); while (nexpos>-1) { //set the distance to -, so we do not visit it again //System.out.println("DSAFA " +nexpos); //System.out.println(distancelist +" "+ movelist+posxlist+posylist); distancelist.set(nexpos,-1*distancelist.get(nexpos)); //add the new distances adjacent to this spot dist_surround(board,posxlist.get(nexpos),posylist.get(nexpos),ex,ey,okmap,distancelist,posxlist,posylist,movelist,movelist.get(nexpos)); nexpos=nextPosition(distancelist); } if (nexpos==-1) { return 0; } else { //switch positions Character c= board[sy][sx]; board[sy][sx]=board[ey][ex]; board[ey][ex]=c; return movelist.get(-1*(nexpos+2)); } } /* int distanceN = Integer.MAX_VALUE; int distanceS = Integer.MAX_VALUE; int distanceE = Integer.MAX_VALUE; int distanceW = Integer.MAX_VALUE; if (sx == ex && sy == ey) return 0; if (safe(board, sx, sy-1)) { //distanceN = distance(sx, ex, sy-1, ey); distanceN = distance(sx, ex, sy-1, ey); } if (safe(board, sx, sy+1)) { distanceS = distance(sx, ex, sy+1, ey); } if (safe(board, sx+1, sy)) { distanceE = distance(sx+1, ex, sy, ey); } if (safe(board, sx-1, sy)) { distanceW = distance(sx-1, ex, sy, ey); } int finalmin=Integer.MAX_VALUE; int min = Math.min(Math.min(Math.min(distanceN, distanceS),distanceE),distanceW); while (min!=Integer.MAX_VALUE) { if (min==distanceN) { finalmin=move(board,sx,ex,sy-1,by); //need to update an array containing where we have visited already } } */ //return min; static int distance(int sx, int sy, int ex, int ey) { //instead of using pythagorean distance, will instead use the least distance possible to get to the point //i.e. a+b, instead of a^2+b^2 return Math.abs(sx-ex)+Math.abs(sy-ey); // return (sx-ex)*(sx-ex) + (sy-ey)*(sy-ey); } static boolean safe(Character[][] board, int x, int y, boolean okmap[][]) { //out pof bounds //System.out.println(x+" "+y+" "+board[0].length+ " "+board.length); if (x<0 || y<0 || x>=board[0].length || y>=board.length) return false; return (board[y][x].equals('E') && okmap[y][x]); } }
dalhousieblack/DAL2
C.java
722
package com.reactlibrary; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.media.MediaPlayer; import android.os.Build; import android.support.v4.app.NotificationCompat; import android.util.Log; import android.widget.RemoteViews; import com.zmxv.RNSound.RNSoundModule; import java.net.URL; class JcNotificationPlayerService { static final String NEXT = "NEXT"; static final String PREVIOUS = "PREVIOUS"; static final String PAUSE = "PAUSE"; static final String PLAY = "PLAY"; static final String ACTION = "ACTION"; static final String PLAYLIST = "PLAYLIST"; static final String CURRENT_AUDIO = "CURRENT_AUDIO"; private static final int NOTIFICATION_ID = 100; private static final int NEXT_ID = 0; private static final int PREVIOUS_ID = 1; private static final int PLAY_ID = 2; private static final int PAUSE_ID = 3; private NotificationManager notificationManager; private Context context; private String title; private String time = "00:00"; private int iconResource; private Notification notification; private NotificationCompat.Builder notificationCompat; MediaPlayer player = RNSoundModule.playerPool.get(1); public JcNotificationPlayerService(Context context){ this.context = context; } public void createNotificationPlayer(String title) { Log.d("JCNotification", "CreateCotificationPlayer"); this.title = title; Intent openUi = new Intent(context, context.getClass()); openUi.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); if (notificationManager == null) { notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { notification = new Notification.Builder(context) .setVisibility(Notification.VISIBILITY_PUBLIC) .setSmallIcon(R.drawable.icon) .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.icon)) .setContent(createNotificationPlayerView()) .setContentIntent(PendingIntent.getActivity(context, NOTIFICATION_ID, openUi, PendingIntent.FLAG_CANCEL_CURRENT)) .setCategory(Notification.CATEGORY_SOCIAL) .build(); //notificationManager.notify(NOTIFICATION_ID, notification); Log.d("notified", "in if"); // Sets an ID for the notification int mNotificationId = 001; // Gets an instance of the NotificationManager service NotificationManager mNotifyMgr = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); // Builds the notification and issues it. mNotifyMgr.notify(mNotificationId, notification); } else { notificationCompat = new NotificationCompat.Builder(context) //TODO: Set to API below Build.VERSION.SDK_INT .setVisibility(Notification.VISIBILITY_PUBLIC) .setSmallIcon(R.drawable.icon) .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.icon)) .setContent(createNotificationPlayerView()) .setContentIntent(PendingIntent.getActivity(context, NOTIFICATION_ID, openUi, PendingIntent.FLAG_CANCEL_CURRENT)) .setCategory(Notification.CATEGORY_SERVICE); notificationManager.notify(NOTIFICATION_ID, notificationCompat.build()); Log.d("notified", "in else"); } } private RemoteViews createNotificationPlayerView() { Log.d("Creating: ", "Pending Intent Play - CNPV"); RemoteViews remoteView; if (player.isPlaying()) { Log.d("player:", "is playing"); remoteView = new RemoteViews(context.getPackageName(), R.layout.notification_pause); remoteView.setOnClickPendingIntent(R.id.btn_pause_notification, buildPendingIntent(PAUSE, 1)); } else { Log.d("player:", "is NOT playing"); remoteView = new RemoteViews(context.getPackageName(), R.layout.notification_play); remoteView.setOnClickPendingIntent(R.id.btn_play_notification, buildPendingIntent(PLAY, 1)); } remoteView.setTextViewText(R.id.txt_current_music_notification, title); remoteView.setTextViewText(R.id.txt_duration_notification, time); return remoteView; } private PendingIntent buildPendingIntent(String action, int id) { Intent playIntent = new Intent(context.getApplicationContext(), com.reactlibrary.JcPlayerNotificationReceiver.class); playIntent.putExtra(ACTION, action); return PendingIntent.getBroadcast(context.getApplicationContext(), id, playIntent, PendingIntent.FLAG_UPDATE_CURRENT); } // // public void onPreparedAudio(String audioName, int duration) { // // } // // public void onCompletedAudio() { // // } // // public void onPaused() { // createNotificationPlayer(title, iconResource); // } // // public void onContinueAudio() { // // } // // public void onPlaying() { // createNotificationPlayer(title, iconResource); // } // // public void onTimeChanged(long currentTime) { // long aux = currentTime / 1000; // int minutes = (int) (aux / 60); // int seconds = (int) (aux % 60); // final String sMinutes = minutes < 10 ? "0" + minutes : minutes + ""; // final String sSeconds = seconds < 10 ? "0" + seconds : seconds + ""; // this.time = sMinutes + ":" + sSeconds; // // createNotificationPlayer(title, iconResource); // } // // public void updateTitle(String title) { // this.title = title; // createNotificationPlayer(title, iconResource); // } // // public void destroyNotificationIfExists() { // if (notificationManager != null) { // try { // notificationManager.cancel(NOTIFICATION_ID); // } catch (NullPointerException e) { // e.printStackTrace(); // } // } // } }
zoecarver/cocoacast
_.java
723
import java.util.ArrayList; import java.util.Scanner; public class TaskListApp { private ArrayList<String> taskList; //define an arraylist private Scanner scanner = new Scanner(System.in); public TaskListApp() { taskList = new ArrayList<>(); //Create an arraylist to store tasks } public void start() { int choice = 1; do { System.out.println("\nTask List Application"); System.out.println("1. Add Task"); System.out.println("2. Remove Task"); System.out.println("3. List Tasks"); System.out.println("4. Exit"); System.out.print("Enter your choice: "); choice = scanner.nextInt(); scanner.nextLine(); // Consume the newline character switch (choice) { case 1: addTask(); break; case 2: removeTask(); break; case 3: listTasks(); break; case 4: System.out.println("Exiting the application. Goodbye!"); break; default: System.out.println("Invalid choice. Please try again."); } } while (choice != 4); } private void addTask() { System.out.print("Enter the task: "); String task = scanner.nextLine(); taskList.add(task); System.out.println("Task added successfully!"); } private void removeTask() { if (taskList.isEmpty()) { System.out.println("Task list is empty. Nothing to remove."); return; } System.out.println("Current Tasks:"); listTasks(); System.out.print("Enter the task number to remove: "); int taskNumber = scanner.nextInt(); scanner.nextLine(); // Consume the newline character if (taskNumber >= 1 && taskNumber <= taskList.size()) { String removedTask = taskList.remove(taskNumber - 1); System.out.println("Task '" + removedTask + "' removed successfully!"); } else { System.out.println("Invalid task number. No task removed."); } } private void listTasks() { if (taskList.isEmpty()) { System.out.println("Task list is empty."); } else { System.out.println("Tasks:"); for (int i = 0; i < taskList.size(); i++) { System.out.println((i + 1) + ". " + taskList.get(i)); } } } public static void main(String[] args) { TaskListApp taskListApp = new TaskListApp(); //Create an instance of class TaskListApp taskListApp.start(); } }
Sindhu-234/slash-mark
Task1
725
interface a { final public int emp_id=42; } class b { public String emp_name="Priya Patil"; } class c extends b implements a { public void display() { long emp_salary=90000; System.out.println("Employee Id is : "+emp_id); System.out.println("Employee Name is : "+emp_name); System.out.println("Employee Salary is : "+emp_salary); } public static void main(String[]args) { c c1 = new c(); c1.display(); } }
PriyaPatil248/JAVAPROGRAM_Folder
c.java
727
public class M { public static void main(String[] args) { String outcome = evenChecker(6); System.out.println(outcome); boolean outcome2 = isEven(6); System.out.println(outcome2); boolean result = isPos(-5); System.out.println(result); } public static String evenChecker(int a) { if (a % 2 == 0) { return "even"; } else { return "odd"; } } public static boolean isEven(int a) { if (a % 2 == 0) { return true; } else { return false; } } public static boolean isPos(int number) { return number > 0; } public static int sequence(int n) { if (isPos(n)) { for (int i = 0; i < n; i = i + 2) { System.out.println(i); } } else { for (int i = n; i <= -1; i++) { if (!isEven(i)) { System.out.println(i); } } } } }
ziaur07/codespaces_tests
M.java
728
//A shop during festival season offers a discount 10 % for purchase made up to Rs. 1000 12 % for //purchase value for Rs. 1000 or more up to Rs. 1500 & 15 % for purchase value of Rs. 1500 or more //write a program to implemen tthe above scheme for a given sales & print out the sales and print //out the sales value,discount and net amount payable by a customer. Create necessary method & //and constructor. import java.util.*; class calcost { int sv,dis; float netv; calcost() { sv=0; dis=0; netv=0; } void netpay(int sv) { if(sv<=1000) { dis=10; } else if(sv> 1000 & sv<1500) { dis=12; } else { dis=15; } netv=sv-((sv*dis)/100); System.out.println("After Discount Net Value=> "+sv+"is => "+netv); } } class p8 { public static void main(String []args) { int n; Scanner Obj=new Scanner(System.in); System.out.println("Enter Purchase Value-> "); n=Obj.nextInt(); calcost Obj1=new calcost(); Obj1.netpay(n); } }
Rutvik5o/Practice-Programming
p8.java
734
import java.util.Scanner; /* Class AVLNode */ class AVLNode { AVLNode left, right; int data; int height; /* Constructor */ public AVLNode() { left = null; right = null; data = 0; height = 0; } /* Constructor */ public AVLNode(int n) { left = null; right = null; data = n; height = 0; } } /* Class AVLTree */ class AVLTree { private AVLNode root; /* Constructor */ public AVLTree() { root = null; } /* Function to check if tree is empty */ public boolean isEmpty() { return root == null; } /* Make the tree logically empty */ public void makeEmpty() { root = null; } /* Function to insert data */ public void insert(int data) { root = insert(data, root); } /* Function to get height of node */ private int height(AVLNode t ) { return t == null ? -1 : t.height; } /* Function to max of left/right node */ private int max(int lhs, int rhs) { return lhs > rhs ? lhs : rhs; } /* Function to insert data recursively */ private AVLNode insert(int x, AVLNode t) { if (t == null) t = new AVLNode(x); else if (x < t.data) { t.left = insert( x, t.left ); if( height( t.left ) - height( t.right ) == 2 ) if( x < t.left.data ) t = rotateWithLeftChild( t ); else t = doubleWithLeftChild( t ); } else if( x > t.data ) { t.right = insert( x, t.right ); if( height( t.right ) - height( t.left ) == 2 ) if( x > t.right.data) t = rotateWithRightChild( t ); else t = doubleWithRightChild( t ); } else ; // Duplicate; do nothing t.height = max( height( t.left ), height( t.right ) ) + 1; return t; } /* Rotate binary tree node with left child */ private AVLNode rotateWithLeftChild(AVLNode k2) { AVLNode k1 = k2.left; k2.left = k1.right; k1.right = k2; k2.height = max( height( k2.left ), height( k2.right ) ) + 1; k1.height = max( height( k1.left ), k2.height ) + 1; return k1; } /* Rotate binary tree node with right child */ private AVLNode rotateWithRightChild(AVLNode k1) { AVLNode k2 = k1.right; k1.right = k2.left; k2.left = k1; k1.height = max( height( k1.left ), height( k1.right ) ) + 1; k2.height = max( height( k2.right ), k1.height ) + 1; return k2; } /** * Double rotate binary tree node: first left child * with its right child; then node k3 with new left child */ private AVLNode doubleWithLeftChild(AVLNode k3) { k3.left = rotateWithRightChild( k3.left ); return rotateWithLeftChild( k3 ); } /** * Double rotate binary tree node: first right child * with its left child; then node k1 with new right child */ private AVLNode doubleWithRightChild(AVLNode k1) { k1.right = rotateWithLeftChild( k1.right ); return rotateWithRightChild( k1 ); } /* Functions to count number of nodes */ public int countNodes() { return countNodes(root); } private int countNodes(AVLNode r) { if (r == null) return 0; else { int l = 1; l += countNodes(r.left); l += countNodes(r.right); return l; } } /* Functions to search for an element */ public int search(int val) { return search(root, val); } private int search(AVLNode r, int val) { int found = -1; while ((r != null) && found==-1) { int rval = r.data; if (val < rval) { if(r.left.data==val) { found = r.data; return found; } r = r.left; } else if (val > rval) { if(r.right.data==val) { found = r.data; return found; } r = r.right; } else { found = -1; break; } found = search(r, val); } return found; } } /* Class AVL Tree Test */ public class AVLTreeTest { public static void main(String[] args) { Scanner scan = new Scanner(System.in); /* Creating object of AVLTree */ AVLTree avlt = new AVLTree(); int a = scan.nextInt(); /* Perform tree operations */ int i = 0; while(i<a) { String choice = scan.next(); int index1=choice.indexOf(" "); char number=choice.charAt(index1+1); int num=Integer.parseInt(number); if(choice.charAt(0)=='A') { int add = Integer.parseInt(choice,choice.charAt(choice.length()-1)); avlt.insert(add); } else if(choice=="PARENT") { int s = Integer.parseInt(choice,choice.charAt(choice.length()-1)); int ans = avlt.search(s); System.out.print(ans); } else { int count = avlt.countNodes(); System.out.print(count); } // switch (choice) // { // case 1 : // System.out.println("Enter integer element to insert"); // avlt.insert( scan.nextInt() ); // break; // case 2 : // System.out.println("Enter integer element to search"); // System.out.println("Search result : "+ avlt.search( scan.nextInt() )); // break; // case 3 : // System.out.println("Nodes = "+ avlt.countNodes()); // break; // case 4 : // System.out.println("Empty status = "+ avlt.isEmpty()); // break; // case 5 : // System.out.println("\nTree Cleared"); // avlt.makeEmpty(); // break; // default : // System.out.println("Wrong Entry \n "); // break; // } // // System.out.println("\nDo you want to continue (Type y or n) \n"); // ch = scan.next().charAt(0); i++; } } }
Chandu2000/Hactober-fest-2021
ok.java